@@ -70,14 +70,11 @@ using FieldDescriptorSet =
7070// Recursively searches the given message to collect extensions.
7171// Returns true if all the extensions can be recognized. The extensions will be
7272// appended in to the extensions parameter.
73- // Returns false when there are unknown fields, in which case the data in the
74- // extensions output parameter is not reliable and should be discarded .
75- bool CollectExtensions (const Message& message, FieldDescriptorSet* extensions) {
73+ // Unknown extensions may be present in the case of option imports and will be
74+ // ignored .
75+ void CollectExtensions (const Message& message, FieldDescriptorSet* extensions) {
7676 const Reflection* reflection = message.GetReflection ();
7777
78- // There are unknown fields that could be extensions, thus this call fails.
79- if (reflection->GetUnknownFields (message).field_count () > 0 ) return false ;
80-
8178 std::vector<const FieldDescriptor*> fields;
8279 reflection->ListFields (message, &fields);
8380
@@ -92,16 +89,14 @@ bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {
9289 for (int j = 0 ; j < size; j++) {
9390 const Message& sub_message =
9491 reflection->GetRepeatedMessage (message, fields[i], j);
95- if (! CollectExtensions (sub_message, extensions)) return false ;
92+ CollectExtensions (sub_message, extensions);
9693 }
9794 } else {
9895 const Message& sub_message = reflection->GetMessage (message, fields[i]);
99- if (! CollectExtensions (sub_message, extensions)) return false ;
96+ CollectExtensions (sub_message, extensions);
10097 }
10198 }
10299 }
103-
104- return true ;
105100}
106101
107102// Finds all extensions for custom options in the given file descriptor with the
@@ -115,7 +110,7 @@ void CollectExtensions(const FileDescriptor& file,
115110 file_proto.GetDescriptor ()->full_name ());
116111
117112 // descriptor.proto is not found in the builder pool, meaning there are no
118- // custom options.
113+ // custom options or they are option imported and not reachable .
119114 if (file_proto_desc == nullptr ) return ;
120115
121116 DynamicMessageFactory factory;
@@ -124,14 +119,10 @@ void CollectExtensions(const FileDescriptor& file,
124119 ABSL_CHECK (dynamic_file_proto.get () != nullptr );
125120 ABSL_CHECK (dynamic_file_proto->ParseFromString (file_data));
126121
127- // Collect the extensions again from the dynamic message.
122+ // Collect the extensions from the dynamic message.
128123 extensions->clear ();
129- ABSL_CHECK (CollectExtensions (*dynamic_file_proto, extensions))
130- << " Found unknown fields in FileDescriptorProto when building "
131- << file_proto.name ()
132- << " . It's likely that those fields are custom options, however, "
133- " those options cannot be recognized in the builder pool. "
134- " This normally should not happen. Please report a bug." ;
124+ // Unknown extensions are ok and expected in the case of option imports.
125+ CollectExtensions (*dynamic_file_proto, extensions);
135126}
136127
137128// Our static initialization methods can become very, very large.
0 commit comments