Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update internalUpdateFileDescriptor() to synchronize setProto() and resolveAllFeatures() to avoid data races. #15659

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions java/core/src/main/java/com/google/protobuf/Descriptors.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ public static void internalUpdateFileDescriptor(
ByteString bytes = descriptor.proto.toByteString();
try {
FileDescriptorProto proto = FileDescriptorProto.parseFrom(bytes, registry);
descriptor.setProto(proto);
synchronized (descriptor) {
descriptor.setProto(proto);
descriptor.resolveAllFeatures();
}
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
"Failed to parse protocol buffer descriptor for generated code.", e);
Expand Down Expand Up @@ -707,7 +710,6 @@ private void setProto(final FileDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());

for (int i = 0; i < messageTypes.length; i++) {
messageTypes[i].setProto(proto.getMessageType(i));
Expand Down Expand Up @@ -1161,7 +1163,6 @@ private void setProto(final DescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());

for (int i = 0; i < nestedTypes.length; i++) {
nestedTypes[i].setProto(proto.getNestedType(i));
Expand Down Expand Up @@ -1978,7 +1979,6 @@ private void setProto(final FieldDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());
}

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

for (int i = 0; i < values.length; i++) {
values[i].setProto(proto.getValue(i));
Expand Down Expand Up @@ -2409,7 +2408,6 @@ private void setProto(final EnumValueDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());
}
}

Expand Down Expand Up @@ -2535,7 +2533,6 @@ private void setProto(final ServiceDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());

for (int i = 0; i < methods.length; i++) {
methods[i].setProto(proto.getMethod(i));
Expand Down Expand Up @@ -2686,7 +2683,6 @@ private void setProto(final MethodDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());
}
}

Expand Down Expand Up @@ -3223,7 +3219,6 @@ private void setProto(final OneofDescriptorProto proto) {
this.proto = proto;
this.features = null;
this.options = null;
this.features = resolveFeatures(proto.getOptions().getFeatures());
}

private OneofDescriptor(
Expand Down
Loading