Force descriptor initialization of dependencies at the beginning of the static init block.

This ensures that any dependent descriptors are already initialized before we use them and we're not initializing them lazily as-we-go. This should help ensure that dependent descriptors are fully initialized before we need them.

PiperOrigin-RevId: 610858264
pull/15977/head
Sandy Zhang 9 months ago committed by Copybara-Service
parent cc55b85a0e
commit 5993e86986
  1. 20
      src/google/protobuf/compiler/java/file.cc

@ -402,6 +402,16 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
"final", options_.opensource_runtime ? "" : "final");
printer->Indent();
// Force descriptor initialization of all dependencies.
for (int i = 0; i < file_->dependency_count(); i++) {
if (ShouldIncludeDependency(file_->dependency(i), true)) {
std::string dependency =
name_resolver_->GetImmutableClassName(file_->dependency(i));
printer->Print("$dependency$.getDescriptor();\n", "dependency",
dependency);
}
}
if (options_.opensource_runtime) {
SharedCodeGenerator shared_code_generator(file_, options_);
shared_code_generator.GenerateDescriptors(printer);
@ -461,16 +471,6 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
});
}
// Force descriptor initialization of all dependencies.
for (int i = 0; i < file_->dependency_count(); i++) {
if (ShouldIncludeDependency(file_->dependency(i), true)) {
std::string dependency =
name_resolver_->GetImmutableClassName(file_->dependency(i));
printer->Print("$dependency$.getDescriptor();\n", "dependency",
dependency);
}
}
if (!extensions.empty()) {
// Must construct an ExtensionRegistry containing all existing extensions
// and use it to parse the descriptor data again to recognize extensions.

Loading…
Cancel
Save