Migrate away from examining the syntax of a proto file via reflection.

PiperOrigin-RevId: 511792205
pull/12023/head
Sandy Zhang 2 years ago committed by Copybara-Service
parent fa82155c65
commit 684a3dedf6
  1. 9
      java/core/src/main/java/com/google/protobuf/DynamicMessage.java

@ -535,11 +535,10 @@ public final class DynamicMessage extends AbstractMessage {
fields.clearField(oldField);
}
oneofCases[index] = field;
} else if (field.getFile().getSyntax() == Descriptors.FileDescriptor.Syntax.PROTO3) {
if (!field.isRepeated()
&& field.getJavaType() != FieldDescriptor.JavaType.MESSAGE
&& value.equals(field.getDefaultValue())) {
// In proto3, setting a field to its default value is equivalent to clearing the field.
} else if (!field.hasPresence()) {
if (!field.isRepeated() && value.equals(field.getDefaultValue())) {
// Setting a field without presence to its default value is equivalent to clearing the
// field.
fields.clearField(field);
return this;
}

Loading…
Cancel
Save