@@ -482,20 +482,17 @@ public static FileDescriptor internalBuildGeneratedFileFrom(
482
482
return internalBuildGeneratedFileFrom (descriptorDataParts , dependencies );
483
483
}
484
484
485
- public static void internalUpdateFileDescriptorImmutable (
485
+ /**
486
+ * This method is to be called by generated code only. It updates the FileDescriptorProto
487
+ * associated with the descriptor by parsing it again with the given ExtensionRegistry. This is
488
+ * needed to recognize custom options.
489
+ */
490
+ public static void internalUpdateFileDescriptor (
486
491
FileDescriptor descriptor , ExtensionRegistry registry ) {
487
- internalUpdateFileDescriptor (descriptor , registry , false );
488
- }
489
-
490
- private static void internalUpdateFileDescriptor (
491
- FileDescriptor descriptor , ExtensionRegistry registry , boolean mutable ) {
492
492
ByteString bytes = descriptor .proto .toByteString ();
493
493
try {
494
494
FileDescriptorProto proto = FileDescriptorProto .parseFrom (bytes , registry );
495
- synchronized (descriptor ) {
496
- descriptor .setProto (proto );
497
- descriptor .resolveAllFeaturesImmutable ();
498
- }
495
+ descriptor .setProto (proto );
499
496
} catch (InvalidProtocolBufferException e ) {
500
497
throw new IllegalArgumentException (
501
498
"Failed to parse protocol buffer descriptor for generated code." , e );
@@ -712,10 +709,10 @@ private void crossLink() throws DescriptorValidationException {
712
709
* construct the descriptors we have to have parsed the descriptor protos. So, we have to parse
713
710
* the descriptor protos a second time after constructing the descriptors.
714
711
*/
715
- private void setProto (final FileDescriptorProto proto ) {
712
+ private synchronized void setProto (final FileDescriptorProto proto ) {
716
713
this .proto = proto ;
717
- this .features = null ;
718
714
this .options = null ;
715
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
719
716
720
717
for (int i = 0 ; i < messageTypes .length ; i ++) {
721
718
messageTypes [i ].setProto (proto .getMessageType (i ));
@@ -1167,8 +1164,8 @@ private void validateNoDuplicateFieldNumbers() throws DescriptorValidationExcept
1167
1164
/** See {@link FileDescriptor#setProto}. */
1168
1165
private void setProto (final DescriptorProto proto ) {
1169
1166
this .proto = proto ;
1170
- this .features = null ;
1171
1167
this .options = null ;
1168
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
1172
1169
1173
1170
for (int i = 0 ; i < nestedTypes .length ; i ++) {
1174
1171
nestedTypes [i ].setProto (proto .getNestedType (i ));
@@ -1983,8 +1980,8 @@ private void crossLink() throws DescriptorValidationException {
1983
1980
/** See {@link FileDescriptor#setProto}. */
1984
1981
private void setProto (final FieldDescriptorProto proto ) {
1985
1982
this .proto = proto ;
1986
- this .features = null ;
1987
1983
this .options = null ;
1984
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
1988
1985
}
1989
1986
1990
1987
/** For internal use only. This is to satisfy the FieldDescriptorLite interface. */
@@ -2263,8 +2260,8 @@ private void resolveAllFeatures() {
2263
2260
/** See {@link FileDescriptor#setProto}. */
2264
2261
private void setProto (final EnumDescriptorProto proto ) {
2265
2262
this .proto = proto ;
2266
- this .features = null ;
2267
2263
this .options = null ;
2264
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
2268
2265
2269
2266
for (int i = 0 ; i < values .length ; i ++) {
2270
2267
values [i ].setProto (proto .getValue (i ));
@@ -2412,8 +2409,8 @@ private void resolveAllFeatures() {
2412
2409
/** See {@link FileDescriptor#setProto}. */
2413
2410
private void setProto (final EnumValueDescriptorProto proto ) {
2414
2411
this .proto = proto ;
2415
- this .features = null ;
2416
2412
this .options = null ;
2413
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
2417
2414
}
2418
2415
}
2419
2416
@@ -2537,8 +2534,8 @@ private void crossLink() throws DescriptorValidationException {
2537
2534
/** See {@link FileDescriptor#setProto}. */
2538
2535
private void setProto (final ServiceDescriptorProto proto ) {
2539
2536
this .proto = proto ;
2540
- this .features = null ;
2541
2537
this .options = null ;
2538
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
2542
2539
2543
2540
for (int i = 0 ; i < methods .length ; i ++) {
2544
2541
methods [i ].setProto (proto .getMethod (i ));
@@ -2687,8 +2684,8 @@ private void crossLink() throws DescriptorValidationException {
2687
2684
/** See {@link FileDescriptor#setProto}. */
2688
2685
private void setProto (final MethodDescriptorProto proto ) {
2689
2686
this .proto = proto ;
2690
- this .features = null ;
2691
2687
this .options = null ;
2688
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
2692
2689
}
2693
2690
}
2694
2691
@@ -3223,8 +3220,8 @@ private void resolveAllFeatures() {
3223
3220
3224
3221
private void setProto (final OneofDescriptorProto proto ) {
3225
3222
this .proto = proto ;
3226
- this .features = null ;
3227
3223
this .options = null ;
3224
+ this .features = resolveFeatures (proto .getOptions ().getFeatures ());
3228
3225
}
3229
3226
3230
3227
private OneofDescriptor (
0 commit comments