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

Nested types are not handled properly #3499

Open
Leonti opened this issue Dec 23, 2024 · 0 comments
Open

Nested types are not handled properly #3499

Leonti opened this issue Dec 23, 2024 · 0 comments

Comments

@Leonti
Copy link
Contributor

Leonti commented Dec 23, 2024

We have recently tried upgrading protobuf-provider package from 7.6.1 to 7.8.0 and noticed that it doesn't handle nested types properly anymore.

Here is a self-contained failing test which I put in ProtobufSchemaTest:

  @Test
  public void testContainedEnum() {
    String sampleProtoFile = "syntax = \"proto2\";\n" +
            "\n" +
            "package sample;\n" +
            "\n" +
            "import \"withenum/imported.proto\";\n" +
            "\n" +
            "message SampleMessage {\n" +
            "\n" +
            "  optional uint64 timestamp = 1;\n" +
            "  optional withenum.ContainingNestedEnum containing_nested_enum = 5;\n" +
            "}\n" +
            "\n" +
            "message Action {\n" +
            "  optional string id = 1;\n" +
            "}";
    String importedProto = "syntax = \"proto2\";\n" +
            "\n" +
            "package withenum;\n" +
            "\n" +
            "message ContainingNestedEnum {\n" +
            "\n" +
            "  optional Action action = 1;\n" +
            "\n" +
            "  enum Action {\n" +
            "    TEST = 1;\n" +
            "  }\n" +
            "}";

    ProtobufSchema protobufSchema = new ProtobufSchema(sampleProtoFile,
            Collections.singletonList(new SchemaReference("withenum/imported.proto", "withenum/imported.proto", 1)),
            new HashMap<String, String>() {{
              put("withenum/imported.proto", importedProto);
            }},
            1,
            "test");
    protobufSchema.toDescriptor();
  }

This fails with:

java.lang.IllegalStateException: com.google.protobuf.Descriptors$DescriptorValidationException: withenum.ContainingNestedEnum.action: "Action" is not a message type.

It looks like it's happening because FieldDefinition.Builder.setType is called with just Action when processing fields of ContainingNestedEnum. Because of that it finds sample.Action in the main package (which is the wrong Action) and sets the type of the field as MESSAGE_TYPE which causes a fail down the line when trying to convert the ProtobufSchema into a Descriptor.
When I call ctx.resolveFull(ctx::getTypeForFullName, "withenum.ContainingNestedEnum.Action", true) from debugger it's able to find the correct Action with the correct EnumElement type.

I'm able to reproduce it with v7.8.0 tag. Similar protos have been working properly in the past until the newer versions.

Cheers,
Leonti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant