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
pull/17147/head
Mike Kruskal 7 months ago committed by Copybara-Service
parent a30b25578a
commit 071d5351eb
  1. 14
      java/core/src/main/java/com/google/protobuf/Descriptors.java

@ -1901,7 +1901,9 @@ public final class Descriptors {
}
}
if (getJavaType() == JavaType.MESSAGE) {
// Use raw type since inferred type considers messageType which may not be fully cross
// linked yet.
if (type.getJavaType() == JavaType.MESSAGE) {
if (!(typeDescriptor instanceof Descriptor)) {
throw new DescriptorValidationException(
this, '\"' + proto.getTypeName() + "\" is not a message type.");
@ -1911,7 +1913,7 @@ public final class Descriptors {
if (proto.hasDefaultValue()) {
throw new DescriptorValidationException(this, "Messages can't have default values.");
}
} else if (getJavaType() == JavaType.ENUM) {
} else if (type.getJavaType() == JavaType.ENUM) {
if (!(typeDescriptor instanceof EnumDescriptor)) {
throw new DescriptorValidationException(
this, '\"' + proto.getTypeName() + "\" is not an enum type.");
@ -1921,7 +1923,7 @@ public final class Descriptors {
throw new DescriptorValidationException(this, "Field with primitive type has type_name.");
}
} else {
if (getJavaType() == JavaType.MESSAGE || getJavaType() == JavaType.ENUM) {
if (type.getJavaType() == JavaType.MESSAGE || type.getJavaType() == JavaType.ENUM) {
throw new DescriptorValidationException(
this, "Field with message or enum type missing type_name.");
}
@ -1942,7 +1944,7 @@ public final class Descriptors {
}
try {
switch (getType()) {
switch (type) {
case INT32:
case SINT32:
case SFIXED32:
@ -2017,7 +2019,7 @@ public final class Descriptors {
if (isRepeated()) {
defaultValue = Collections.emptyList();
} else {
switch (getJavaType()) {
switch (type.getJavaType()) {
case ENUM:
// We guarantee elsewhere that an enum type always has at least
// one possible value.
@ -2027,7 +2029,7 @@ public final class Descriptors {
defaultValue = null;
break;
default:
defaultValue = getJavaType().defaultDefault;
defaultValue = type.getJavaType().defaultDefault;
break;
}
}

Loading…
Cancel
Save