diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index df36ce4a37e4..92240d6c3c9b 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -639,7 +639,7 @@ private void resolveAllFeaturesInternal() throws DescriptorValidationException { if (this.features != null) { return; } - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (Descriptor messageType : messageTypes) { messageType.resolveAllFeatures(); @@ -718,7 +718,7 @@ private synchronized void setProto(final FileDescriptorProto proto) { this.proto = proto; this.options = null; try { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (int i = 0; i < messageTypes.length; i++) { messageTypes[i].setProto(proto.getMessageType(i)); @@ -1112,7 +1112,7 @@ private Descriptor( /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (Descriptor nestedType : nestedTypes) { nestedType.resolveAllFeatures(); @@ -1174,7 +1174,7 @@ private void validateNoDuplicateFieldNumbers() throws DescriptorValidationExcept private void setProto(final DescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (int i = 0; i < nestedTypes.length; i++) { nestedTypes[i].setProto(proto.getNestedType(i)); @@ -1744,7 +1744,7 @@ private FieldDescriptor( /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } @Override @@ -1803,7 +1803,7 @@ boolean hasInferredLegacyProtoFeatures() { } @Override - void validateFeatures(FeatureSet features) throws DescriptorValidationException { + void validateFeatures() throws DescriptorValidationException { if (containingType != null && containingType.toProto().getOptions().getMessageSetWireFormat()) { if (isExtension()) { @@ -1992,7 +1992,7 @@ private void crossLink() throws DescriptorValidationException { private void setProto(final FieldDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } /** For internal use only. This is to satisfy the FieldDescriptorLite interface. */ @@ -2262,7 +2262,8 @@ private EnumDescriptor( /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); + for (EnumValueDescriptor value : values) { value.resolveAllFeatures(); } @@ -2272,7 +2273,7 @@ private void resolveAllFeatures() throws DescriptorValidationException { private void setProto(final EnumDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (int i = 0; i < values.length; i++) { values[i].setProto(proto.getValue(i)); @@ -2414,7 +2415,7 @@ private EnumValueDescriptor(final EnumDescriptor parent, final Integer number) { /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } /** See {@link FileDescriptor#setProto}. */ @@ -2422,7 +2423,7 @@ private void setProto(final EnumValueDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } } @@ -2530,7 +2531,7 @@ private ServiceDescriptor( /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (MethodDescriptor method : methods) { method.resolveAllFeatures(); @@ -2547,7 +2548,7 @@ private void crossLink() throws DescriptorValidationException { private void setProto(final ServiceDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); for (int i = 0; i < methods.length; i++) { methods[i].setProto(proto.getMethod(i)); @@ -2668,7 +2669,7 @@ private MethodDescriptor( /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } private void crossLink() throws DescriptorValidationException { @@ -2697,7 +2698,7 @@ private void crossLink() throws DescriptorValidationException { private void setProto(final MethodDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } } @@ -2735,11 +2736,13 @@ private GenericDescriptor() {} public abstract FileDescriptor getFile(); - FeatureSet resolveFeatures(FeatureSet unresolvedFeatures) throws DescriptorValidationException { + void resolveFeatures(FeatureSet unresolvedFeatures) throws DescriptorValidationException { if (this.parent != null && unresolvedFeatures.equals(FeatureSet.getDefaultInstance()) && !hasInferredLegacyProtoFeatures()) { - return this.parent.features; + this.features = this.parent.features; + validateFeatures(); + return; } FeatureSet.Builder features; if (this.parent == null) { @@ -2750,8 +2753,8 @@ FeatureSet resolveFeatures(FeatureSet unresolvedFeatures) throws DescriptorValid } features.mergeFrom(inferLegacyProtoFeatures()); features.mergeFrom(unresolvedFeatures); - validateFeatures(features.build()); - return internFeatures(features.build()); + this.features = internFeatures(features.build()); + validateFeatures(); } FeatureSet inferLegacyProtoFeatures() { @@ -2762,8 +2765,7 @@ boolean hasInferredLegacyProtoFeatures() { return false; } - void validateFeatures(FeatureSet features) throws DescriptorValidationException { - } + void validateFeatures() throws DescriptorValidationException {} GenericDescriptor parent; volatile FeatureSet features; @@ -3231,13 +3233,13 @@ boolean isSynthetic() { /** See {@link FileDescriptor#resolveAllFeatures}. */ private void resolveAllFeatures() throws DescriptorValidationException { - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } private void setProto(final OneofDescriptorProto proto) throws DescriptorValidationException { this.proto = proto; this.options = null; - this.features = resolveFeatures(proto.getOptions().getFeatures()); + resolveFeatures(proto.getOptions().getFeatures()); } private OneofDescriptor(