diff --git a/src/google/protobuf/compiler/retention.cc b/src/google/protobuf/compiler/retention.cc index fad5fd0da8..a8212cddf5 100644 --- a/src/google/protobuf/compiler/retention.cc +++ b/src/google/protobuf/compiler/retention.cc @@ -102,10 +102,13 @@ void ConvertToDynamicMessageAndStripOptions( const Descriptor* descriptor = pool.FindMessageTypeByName(m.GetTypeName()); std::vector path; - if (descriptor == nullptr) { + if (descriptor == nullptr || + descriptor->file()->pool() == DescriptorPool::generated_pool()) { // If the pool does not contain the descriptor, then this proto file does // not transitively depend on descriptor.proto, in which case we know there - // are no custom options to worry about. + // are no custom options to worry about. If we are working with the + // generated pool, then we can still access any custom options without + // having to resort to DynamicMessage. StripMessage(m, path, stripped_paths); } else { DynamicMessageFactory factory;