diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 0a5bfda6bb93..9c4980fcbe22 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -2459,7 +2459,11 @@ public void clear(final GeneratedMessageV3.Builder builder) { final String containingOneofCamelCaseName) { isOneofField = descriptor.getRealContainingOneof() != null; - hasHasMethod = descriptor.hasPresence(); + hasHasMethod = + descriptor.getFile().getSyntax() == FileDescriptor.Syntax.EDITIONS && descriptor.hasPresence() + || descriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO2 + || descriptor.hasOptionalKeyword() + || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); ReflectionInvoker reflectionInvoker = new ReflectionInvoker( descriptor,