What version of protobuf and what language are you using?
Latest Go protobuf from google.golang.org
What did you do? https://go.dev/play/p/GODvwndWw9T
What did you expect to see?
I'd expect that the function doesn't panic and it returns false
.
What did you see instead?
The function panicked: panic: runtime error: invalid memory address or nil pointer dereference
Comment From: puellanivis
func (m *Message) IsValid() bool {
return m.known != nil
}
https://github.com/protocolbuffers/protobuf-go/blob/v1.36.6/types/dynamicpb/dynamic.go#L335-L339
Yep, that would do it.
P.S. An even more minimal replication is to just call IsValid
on the (*dynamicpb.Message)(nil)
itself.
Comment From: neild
protoreflect.Message.IsValid
reports whether a message is an "empty, read-only value". This basically corresponds to a nil pointer to some concrete, generated protobuf type: The type of the message is known, but you can't modify it.
A nil dynamicpb.Message
does not have a protobuf message type. It's not "invalid" in the sense of the IsValid
method, but entirely unusable.
Perhaps the documentation could be clearer, but this is working as intended.