Skip to content

Commit 3d71e22

Browse files
Fix data race in crosslink.
This was introduced by the previous fix for delimited inheritance, and was never released. This fix removes all getType() calls from crosslink, where it's not safe to inspect the message type, which is still a placeholder, until after crosslinking. Using the inferred type is not necessary since we treat messages and groups the same during crosslink. PiperOrigin-RevId: 643394981
1 parent 29f1b52 commit 3d71e22

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,9 @@ private void crossLink() throws DescriptorValidationException {
19011901
}
19021902
}
19031903

1904-
if (getJavaType() == JavaType.MESSAGE) {
1904+
// Use raw type since inferred type considers messageType which may not be fully cross
1905+
// linked yet.
1906+
if (type.getJavaType() == JavaType.MESSAGE) {
19051907
if (!(typeDescriptor instanceof Descriptor)) {
19061908
throw new DescriptorValidationException(
19071909
this, '\"' + proto.getTypeName() + "\" is not a message type.");
@@ -1911,7 +1913,7 @@ private void crossLink() throws DescriptorValidationException {
19111913
if (proto.hasDefaultValue()) {
19121914
throw new DescriptorValidationException(this, "Messages can't have default values.");
19131915
}
1914-
} else if (getJavaType() == JavaType.ENUM) {
1916+
} else if (type.getJavaType() == JavaType.ENUM) {
19151917
if (!(typeDescriptor instanceof EnumDescriptor)) {
19161918
throw new DescriptorValidationException(
19171919
this, '\"' + proto.getTypeName() + "\" is not an enum type.");
@@ -1921,7 +1923,7 @@ private void crossLink() throws DescriptorValidationException {
19211923
throw new DescriptorValidationException(this, "Field with primitive type has type_name.");
19221924
}
19231925
} else {
1924-
if (getJavaType() == JavaType.MESSAGE || getJavaType() == JavaType.ENUM) {
1926+
if (type.getJavaType() == JavaType.MESSAGE || type.getJavaType() == JavaType.ENUM) {
19251927
throw new DescriptorValidationException(
19261928
this, "Field with message or enum type missing type_name.");
19271929
}
@@ -1942,7 +1944,7 @@ private void crossLink() throws DescriptorValidationException {
19421944
}
19431945

19441946
try {
1945-
switch (getType()) {
1947+
switch (type) {
19461948
case INT32:
19471949
case SINT32:
19481950
case SFIXED32:
@@ -2017,7 +2019,7 @@ private void crossLink() throws DescriptorValidationException {
20172019
if (isRepeated()) {
20182020
defaultValue = Collections.emptyList();
20192021
} else {
2020-
switch (getJavaType()) {
2022+
switch (type.getJavaType()) {
20212023
case ENUM:
20222024
// We guarantee elsewhere that an enum type always has at least
20232025
// one possible value.
@@ -2027,7 +2029,7 @@ private void crossLink() throws DescriptorValidationException {
20272029
defaultValue = null;
20282030
break;
20292031
default:
2030-
defaultValue = getJavaType().defaultDefault;
2032+
defaultValue = type.getJavaType().defaultDefault;
20312033
break;
20322034
}
20332035
}

0 commit comments

Comments
 (0)