Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions java/core/src/main/java/com/google/protobuf/Descriptors.java
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,13 @@ public EnumDescriptor findEnumTypeByName(final String name) {
DescriptorProto.newBuilder()
.setName(name)
.addExtensionRange(
DescriptorProto.ExtensionRange.newBuilder().setStart(1).setEnd(536870912).build())
DescriptorProto.ExtensionRange.newBuilder()
.setStart(1)
// 2^31 - 1, which is the largest possible extension for messages that set
// message_set_wire_format = true. Since this is a placeholder and we don't
// have a schema, this is safest setting.
.setEnd(2147483647)
.build())
.build();
this.fullName = fullname;

Expand All @@ -1165,8 +1171,8 @@ public EnumDescriptor findEnumTypeByName(final String name) {
// Create a placeholder FileDescriptor to hold this message.
this.parent = new FileDescriptor(packageName, this);

extensionRangeLowerBounds = new int[] {1};
extensionRangeUpperBounds = new int[] {536870912};
extensionRangeLowerBounds = new int[] {this.proto.getExtensionRange(0).getStart()};
extensionRangeUpperBounds = new int[] {this.proto.getExtensionRange(0).getEnd()};

placeholder = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,31 @@ public void testUnknownFieldsAllowed() throws Exception {
.isTrue();
}

@Test
public void testUnknownMessageSetExtension() throws Exception {
FileDescriptorProto fooProto =
FileDescriptorProto.newBuilder()
.setName("foo.proto")
.addDependency("message_set.proto")
.addExtension(
FieldDescriptorProto.newBuilder()
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
.setType(FieldDescriptorProto.Type.TYPE_INT32)
.setExtendee("MessageSet")
.setName("bar")
.setNumber(2147476052))
.build();

FileDescriptor foo =
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true);
FieldDescriptor field = foo.findExtensionByName("bar");

assertThat(field.isExtension()).isTrue();
assertThat(field.getNumber()).isEqualTo(2147476052);
assertThat(field.getContainingType().isPlaceholder()).isTrue();
assertThat(field.getContainingType().getFullName()).isEqualTo("MessageSet");
}

@Test
public void testHiddenDependency() throws Exception {
FileDescriptorProto barProto =
Expand Down
Loading