[hotfix] Use explicit UTF-8 charset in coerceToBytes and guard Optional.get() in Kafka serializers#4427
Open
dangzitou wants to merge 1 commit into
Open
[hotfix] Use explicit UTF-8 charset in coerceToBytes and guard Optional.get() in Kafka serializers#4427dangzitou wants to merge 1 commit into
dangzitou wants to merge 1 commit into
Conversation
98af393 to
64bdcdb
Compare
…onnectors Fix platform-default charset usage in String.getBytes() calls: - SchemaMergingUtils.coerceToBytes() - DebeziumJsonSerializationSchema.convertDefaultValue() - RowDataTiKVEventDeserializationSchemaBase (TiDB connector) - SchemaMergingUtilsTest, BinaryTypeReturningClass, VarBinaryTypeReturningClass Fix unchecked Optional.get() on schema column lookups: - CsvSerializationSchema / JsonSerializationSchema (Kafka) - DorisMetadataApplier / DorisSchemaUtils (Doris) - StarRocksUtils (StarRocks) All .getBytes() now use StandardCharsets.UTF_8 explicitly. All .get() replaced with .orElseThrow() with descriptive error messages.
64bdcdb to
2d8ab29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
This PR fixes two minor but important issues:
1. Platform-default charset in
SchemaMergingUtils.coerceToBytes()File:
flink-cdc-common/.../SchemaMergingUtils.java:617originalField.toString().getBytes()uses the platform-default charset, which can vary across JVM configurations and operating systems. This causes inconsistent behavior when converting fields to bytes during schema evolution.Fix: Use
StandardCharsets.UTF_8explicitly.2. Unchecked
Optional.get()in Kafka serialization schemasFiles:
CsvSerializationSchema.java:109JsonSerializationSchema.java:132Both files call
schema.getColumn(...).get()without checking if the Optional is present. If a primary key column is missing from the schema (e.g., after schema evolution), this throws a bareNoSuchElementExceptionwith no context.Fix: Replace with
orElseThrow()that includes the missing column name in the error message.Testing
These are straightforward defensive improvements: