diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 03da25a895..848ee90ce0 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/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.