From 49fdc9d1cd1c8194d552b5f04be83ab62b27ef06 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 7 Feb 2024 14:21:26 -0800 Subject: [PATCH] Rewrote the comment about the `java_string_check_utf8` option to fix a few errors and omissions. - The comment stated that the option does not affect lite, but this appears to be false: in my testing the option affects both lite and full protos. - The comment failed to mention that the option has no effect when set explicitly to false. It can only be used to opt proto2 into extra checking, it cannot opt proto3 out of the checks. PiperOrigin-RevId: 605097398 --- src/google/protobuf/descriptor.proto | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 8f619e85cd..6805b9b4b6 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -448,12 +448,16 @@ message FileOptions { // This option does nothing. optional bool java_generate_equals_and_hash = 20 [deprecated=true]; - // If set true, then the Java2 code generator will generate code that - // throws an exception whenever an attempt is made to assign a non-UTF-8 - // byte sequence to a string field. - // Message reflection will do the same. - // However, an extension field still accepts non-UTF-8 byte sequences. - // This option has no effect on when used with the lite runtime. + // A proto2 file can set this to true to opt in to UTF-8 checking for Java, + // which will throw an exception if invalid UTF-8 is parsed from the wire or + // assigned to a string field. + // + // TODO: clarify exactly what kinds of field types this option + // applies to, and update these docs accordingly. + // + // Proto3 files already perform these checks. Setting the option explicitly to + // false has no effect: it cannot be used to opt proto3 files out of UTF-8 + // checks. optional bool java_string_check_utf8 = 27 [default = false]; // Generated classes can be optimized for speed or code size.