mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
reflect/protodesc: don't panic on nil Resolver
The change to make protodesc.NewFile take an interface rather than a concrete type means that NewFile(f, nil) now causes a panic. (A nil *protoregistry.Files is valid.) Fix this panic by using a default, empty registry when NewFile's second parameter is nil. Change-Id: I70a1f0759e7ea5b57fba5b6123ee85188f4d560c Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/182979 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
parent
5857a5ab4f
commit
3631e225f8
@ -13,6 +13,7 @@ import (
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/prototype"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
@ -53,6 +54,9 @@ type Resolver interface {
|
||||
// The caller must relinquish full ownership of the input fd and must not
|
||||
// access or mutate any fields.
|
||||
func NewFile(fd *descriptorpb.FileDescriptorProto, r Resolver) (protoreflect.FileDescriptor, error) {
|
||||
if r == nil {
|
||||
r = (*protoregistry.Files)(nil) // empty resolver
|
||||
}
|
||||
var f prototype.File
|
||||
switch fd.GetSyntax() {
|
||||
case "proto2", "":
|
||||
|
Loading…
Reference in New Issue
Block a user