@@ -70,14 +70,11 @@ using FieldDescriptorSet =
70
70
// Recursively searches the given message to collect extensions.
71
71
// Returns true if all the extensions can be recognized. The extensions will be
72
72
// 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) {
76
76
const Reflection* reflection = message.GetReflection ();
77
77
78
- // There are unknown fields that could be extensions, thus this call fails.
79
- if (reflection->GetUnknownFields (message).field_count () > 0 ) return false ;
80
-
81
78
std::vector<const FieldDescriptor*> fields;
82
79
reflection->ListFields (message, &fields);
83
80
@@ -92,16 +89,14 @@ bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {
92
89
for (int j = 0 ; j < size; j++) {
93
90
const Message& sub_message =
94
91
reflection->GetRepeatedMessage (message, fields[i], j);
95
- if (! CollectExtensions (sub_message, extensions)) return false ;
92
+ CollectExtensions (sub_message, extensions);
96
93
}
97
94
} else {
98
95
const Message& sub_message = reflection->GetMessage (message, fields[i]);
99
- if (! CollectExtensions (sub_message, extensions)) return false ;
96
+ CollectExtensions (sub_message, extensions);
100
97
}
101
98
}
102
99
}
103
-
104
- return true ;
105
100
}
106
101
107
102
// Finds all extensions for custom options in the given file descriptor with the
@@ -115,7 +110,7 @@ void CollectExtensions(const FileDescriptor& file,
115
110
file_proto.GetDescriptor ()->full_name ());
116
111
117
112
// 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 .
119
114
if (file_proto_desc == nullptr ) return ;
120
115
121
116
DynamicMessageFactory factory;
@@ -124,14 +119,10 @@ void CollectExtensions(const FileDescriptor& file,
124
119
ABSL_CHECK (dynamic_file_proto.get () != nullptr );
125
120
ABSL_CHECK (dynamic_file_proto->ParseFromString (file_data));
126
121
127
- // Collect the extensions again from the dynamic message.
122
+ // Collect the extensions from the dynamic message.
128
123
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);
135
126
}
136
127
137
128
// Our static initialization methods can become very, very large.
0 commit comments