Skip to content

Commit

Permalink
Explicitly reject fields that are closed enums with implicit presence…
Browse files Browse the repository at this point in the history
… in Java generators.

The normal case of this is already rejected by the .proto parser, this additional check covers legacy_closed_enum cases. Those cases will otherwise reach a CHECK-fail, this just makes for a clearer error message that this is simply a disallowed combination.

PiperOrigin-RevId: 696587446
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 14, 2024
1 parent 6ceef1c commit 80a9003
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/google/protobuf/compiler/java/generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ TEST_F(JavaGeneratorTest, BasicError) {
"foo.proto:4:7: Expected \"required\", \"optional\", or \"repeated\"");
}

TEST_F(JavaGeneratorTest, ImplicitPresenceLegacyClosedEnumDisallowed) {
CreateTempFile("foo.proto",
R"schema(
edition = "2023";
import "third_party/java/protobuf/java_features.proto";
option features.field_presence = IMPLICIT;
enum Bar {
AAA = 0;
}
message Foo {
Bar bar = 1 [features.(pb.java).legacy_closed_enum = true];
}
)schema");

RunProtoc(
"protocol_compiler --proto_path=$tmpdir --java_out=$tmpdir foo.proto");

ExpectErrorSubstring(
"foo.proto: Field Foo.bar has a closed enum type with implicit "
"presence.");
}


} // namespace
} // namespace java
Expand Down

0 comments on commit 80a9003

Please sign in to comment.