Skip to content

Commit 0cd260a

Browse files
Document that utf8_validation=NONE takes no effects on map<string, ...> in java protobuf
PiperOrigin-RevId: 914960862
1 parent fc39a29 commit 0cd260a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

content/editions/features.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ where there's a language-specific `utf8_validation` feature that overrides it.
572572
See [`features.(pb.java).utf8_validation`](#java-utf8_validation) for the
573573
Java-language-specific feature.
574574

575+
**Important:** In Java, `map<string, ...>` fields always undergo UTF-8
576+
validation, even when `utf8_validation = NONE` is configured. Because Java keys
577+
will be represented as `java.lang.String` objects, disabling validation would
578+
force the runtime to convert invalid byte sequences *lossily* using replacement
579+
characters. This lossy conversion can result in unexpected behavior, such as key
580+
collisions. As a wire-compatible workaround, consider using a `repeated` field
581+
with a custom "map entry" message instead.
582+
575583
This feature doesn't impact proto3 files, so this section doesn't have a before
576584
and after of a proto3 file.
577585

0 commit comments

Comments
 (0)