Skip to content

Commit 225b080

Browse files
authored
Update internalUpdateFileDescriptor() to synchronize setProto() and resolveAllFeatures() to avoid data races. (#15659)
PiperOrigin-RevId: 601628994
1 parent 77efb8d commit 225b080

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

java/core/src/main/java/com/google/protobuf/Descriptors.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ public static void internalUpdateFileDescriptor(
490490
ByteString bytes = descriptor.proto.toByteString();
491491
try {
492492
FileDescriptorProto proto = FileDescriptorProto.parseFrom(bytes, registry);
493-
descriptor.setProto(proto);
493+
synchronized (descriptor) {
494+
descriptor.setProto(proto);
495+
descriptor.resolveAllFeatures();
496+
}
494497
} catch (InvalidProtocolBufferException e) {
495498
throw new IllegalArgumentException(
496499
"Failed to parse protocol buffer descriptor for generated code.", e);
@@ -707,7 +710,6 @@ private void setProto(final FileDescriptorProto proto) {
707710
this.proto = proto;
708711
this.features = null;
709712
this.options = null;
710-
this.features = resolveFeatures(proto.getOptions().getFeatures());
711713

712714
for (int i = 0; i < messageTypes.length; i++) {
713715
messageTypes[i].setProto(proto.getMessageType(i));
@@ -1161,7 +1163,6 @@ private void setProto(final DescriptorProto proto) {
11611163
this.proto = proto;
11621164
this.features = null;
11631165
this.options = null;
1164-
this.features = resolveFeatures(proto.getOptions().getFeatures());
11651166

11661167
for (int i = 0; i < nestedTypes.length; i++) {
11671168
nestedTypes[i].setProto(proto.getNestedType(i));
@@ -1978,7 +1979,6 @@ private void setProto(final FieldDescriptorProto proto) {
19781979
this.proto = proto;
19791980
this.features = null;
19801981
this.options = null;
1981-
this.features = resolveFeatures(proto.getOptions().getFeatures());
19821982
}
19831983

19841984
/** For internal use only. This is to satisfy the FieldDescriptorLite interface. */
@@ -2259,7 +2259,6 @@ private void setProto(final EnumDescriptorProto proto) {
22592259
this.proto = proto;
22602260
this.features = null;
22612261
this.options = null;
2262-
this.features = resolveFeatures(proto.getOptions().getFeatures());
22632262

22642263
for (int i = 0; i < values.length; i++) {
22652264
values[i].setProto(proto.getValue(i));
@@ -2409,7 +2408,6 @@ private void setProto(final EnumValueDescriptorProto proto) {
24092408
this.proto = proto;
24102409
this.features = null;
24112410
this.options = null;
2412-
this.features = resolveFeatures(proto.getOptions().getFeatures());
24132411
}
24142412
}
24152413

@@ -2535,7 +2533,6 @@ private void setProto(final ServiceDescriptorProto proto) {
25352533
this.proto = proto;
25362534
this.features = null;
25372535
this.options = null;
2538-
this.features = resolveFeatures(proto.getOptions().getFeatures());
25392536

25402537
for (int i = 0; i < methods.length; i++) {
25412538
methods[i].setProto(proto.getMethod(i));
@@ -2686,7 +2683,6 @@ private void setProto(final MethodDescriptorProto proto) {
26862683
this.proto = proto;
26872684
this.features = null;
26882685
this.options = null;
2689-
this.features = resolveFeatures(proto.getOptions().getFeatures());
26902686
}
26912687
}
26922688

@@ -3223,7 +3219,6 @@ private void setProto(final OneofDescriptorProto proto) {
32233219
this.proto = proto;
32243220
this.features = null;
32253221
this.options = null;
3226-
this.features = resolveFeatures(proto.getOptions().getFeatures());
32273222
}
32283223

32293224
private OneofDescriptor(

0 commit comments

Comments
 (0)