flink-cdc icon indicating copy to clipboard operation
flink-cdc copied to clipboard

[hotfix] Use explicit UTF-8 charset in getBytes() calls across connectors

Open dangzitou opened this issue 5 months ago • 0 comments

What this PR does

Replaces platform-default String.getBytes() with String.getBytes(StandardCharsets.UTF_8) across multiple modules to ensure consistent encoding behavior regardless of JVM locale or OS configuration.

Affected files

  • SchemaMergingUtils.java + test — core schema coercion
  • DebeziumJsonSerializationSchema.java — Kafka Debezium JSON default value handling
  • RowDataTiKVEventDeserializationSchemaBase.java — TiDB source connector
  • BinaryTypeReturningClass.java / VarBinaryTypeReturningClass.java — UDF examples

Why

String.getBytes() without an explicit charset uses the JVM's default charset, which varies across environments (e.g., US-ASCII on some minimal Docker images, GBK on Chinese Windows). This causes silent data corruption when non-ASCII characters are involved. Using UTF-8 explicitly makes the behavior deterministic.

Testing

These are straightforward defensive improvements — the fix ensures consistent UTF-8 encoding regardless of JVM locale.


Split from #4427 as requested by @yuxiqian.

dangzitou avatar Jun 04 '26 01:06 dangzitou