diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 199740620b..7d971b35f8 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -2237,9 +2237,13 @@ class PROTOBUF_EXPORT DescriptorPool { // Asynchronous execution is undefined behavior. void SetRecursiveBuildDispatcher( absl::AnyInvocable) const> dispatcher) { - dispatcher_ = std::make_unique< - absl::AnyInvocable) const>>( - std::move(dispatcher)); + if (dispatcher != nullptr) { + dispatcher_ = std::make_unique< + absl::AnyInvocable) const>>( + std::move(dispatcher)); + } else { + dispatcher_.reset(nullptr); + } } #endif // SWIG