Protobuf Java cross-domain Poison Pills.

PiperOrigin-RevId: 597335599
pull/15259/head
Protobuf Team Bot 11 months ago committed by Copybara-Service
parent 6820a563e2
commit 686cfc6ab5
  1. 12
      src/google/protobuf/compiler/java/file.cc
  2. 33
      src/google/protobuf/compiler/java/helpers.cc
  3. 2
      src/google/protobuf/compiler/java/helpers.h
  4. 12
      src/google/protobuf/compiler/java/message.cc
  5. 4
      src/google/protobuf/compiler/java/shared_code_generator.cc

@ -273,13 +273,11 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Annotate("classname", file_->name());
printer->Indent();
if (options_.opensource_runtime) {
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer);
printer->Outdent();
printer->Print("}\n");
}
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer, options_.opensource_runtime);
printer->Outdent();
printer->Print("}\n");
// -----------------------------------------------------------------

@ -85,19 +85,26 @@ void PrintEnumVerifierLogic(
absl::StrCat(enum_verifier_string, terminating_string));
}
void PrintGencodeVersionValidator(io::Printer* printer) {
const auto& version = GetProtobufJavaVersion();
printer->Print(
"com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n"
" com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC,\n"
" $major$,\n"
" $minor$,\n"
" $patch$,\n"
" $suffix$);\n",
"major", absl::StrCat("/* major= */ ", version.major()), "minor",
absl::StrCat("/* minor= */ ", version.minor()), "patch",
absl::StrCat("/* patch= */ ", version.patch()), "suffix",
absl::StrCat("/* suffix= */ \"", version.suffix(), "\""));
void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime) {
if (oss_runtime) {
const auto& version = GetProtobufJavaVersion();
printer->Print(
"com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n"
" com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC,\n"
" $major$,\n"
" $minor$,\n"
" $patch$,\n"
" $suffix$);\n",
"major", absl::StrCat("/* major= */ ", version.major()), "minor",
absl::StrCat("/* minor= */ ", version.minor()), "patch",
absl::StrCat("/* patch= */ ", version.patch()), "suffix",
absl::StrCat("/* suffix= */ \"", version.suffix(), "\""));
} else {
printer->Print(
"com.google.protobuf.RuntimeVersion.validateProtobufGencodeDomain(\n"
" "
"com.google.protobuf.RuntimeVersion.RuntimeDomain.GOOGLE_INTERNAL);\n");
}
}
std::string UnderscoresToCamelCase(absl::string_view input,

@ -61,7 +61,7 @@ void PrintEnumVerifierLogic(
// Prints the Protobuf Java Version validator checking that the runtime and
// gencode versions are compatible.
void PrintGencodeVersionValidator(io::Printer* printer);
void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime);
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
// first letter.

@ -341,13 +341,11 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
printer->Indent();
if (context_->options().opensource_runtime) {
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer);
printer->Outdent();
printer->Print("}\n");
}
printer->Print("static {\n");
printer->Indent();
PrintGencodeVersionValidator(printer, context_->options().opensource_runtime);
printer->Outdent();
printer->Print("}\n");
// Using builder_type, instead of Builder, prevents the Builder class from
// being loaded into PermGen space when the default instance is created.

@ -94,9 +94,7 @@ void SharedCodeGenerator::Generate(
printer->Indent();
printer->Indent();
GenerateDescriptors(printer.get());
if (options_.opensource_runtime) {
PrintGencodeVersionValidator(printer.get());
}
PrintGencodeVersionValidator(printer.get(), options_.opensource_runtime);
printer->Outdent();
printer->Outdent();
printer->Print(

Loading…
Cancel
Save