diff --git a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs b/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs deleted file mode 100644 index 208ce1fcb6..0000000000 --- a/csharp/src/Google.Protobuf/Reflection/FeatureSetDescriptor.g.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd -#endregion - -namespace Google.Protobuf.Reflection; - -internal sealed partial class FeatureSetDescriptor -{ - // Canonical serialized form of the edition defaults, generated by embed_edition_defaults. - private const string DefaultsBase64 = - "ChMYhAciACoMCAEQAhgCIAMoATACChMY5wciACoMCAIQARgBIAIoATABChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH"; -} diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index c4eb3752d2..34aad86670 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -240,6 +240,17 @@ bool FileGenerator::Validate(std::string* error) { << "name for the .proto file to be safe."; } + // Check that no field is a closed enum with implicit presence. For normal + // cases this will be rejected by protoc before the generator is invoked, but + // for cases like legacy_closed_enum it may reach the generator. + google::protobuf::internal::VisitDescriptors(*file_, [&](const FieldDescriptor& field) { + if (field.enum_type() != nullptr && !SupportUnknownEnumValue(&field) && + !field.has_presence() && !field.is_repeated()) { + absl::StrAppend(error, "Field ", field.full_name(), + " has a closed enum type with implicit presence.\n"); + } + }); + // Print a warning if optimize_for = LITE_RUNTIME is used. if (file_->options().optimize_for() == FileOptions::LITE_RUNTIME && !options_.enforce_lite) { diff --git a/src/google/protobuf/compiler/java/generator_unittest.cc b/src/google/protobuf/compiler/java/generator_unittest.cc index 8552840bee..55725d3b3d 100644 --- a/src/google/protobuf/compiler/java/generator_unittest.cc +++ b/src/google/protobuf/compiler/java/generator_unittest.cc @@ -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