diff --git a/cmd/protoc-gen-go/internal_gengo/well_known_types.go b/cmd/protoc-gen-go/internal_gengo/well_known_types.go index 8b12823f..7f6ca2c3 100644 --- a/cmd/protoc-gen-go/internal_gengo/well_known_types.go +++ b/cmd/protoc-gen-go/internal_gengo/well_known_types.go @@ -54,13 +54,13 @@ func genMessageKnownFunctions(g *protogen.GeneratedFile, f *fileInfo, m *message g.P("//") g.P("// If no options are specified, call src.UnmarshalTo instead.") g.P("func UnmarshalTo(src *Any, dst ", protoPackage.Ident("Message"), ", opts ", protoPackage.Ident("UnmarshalOptions"), ") error {") - g.P(" if src.GetTypeUrl() == \"\" {") - g.P(" return ", protoimplPackage.Ident("X"), ".NewError(\"invalid empty type URL\")") + g.P(" if src == nil {") + g.P(" return ", protoimplPackage.Ident("X"), ".NewError(\"invalid nil source message\")") g.P(" }") g.P(" if !src.MessageIs(dst) {") g.P(" got := dst.ProtoReflect().Descriptor().FullName()") g.P(" want := src.MessageName()") - g.P(" return ", protoimplPackage.Ident("X"), ".NewError(\"mismatching message types: got %q, want %q\", got, want)") + g.P(" return ", protoimplPackage.Ident("X"), ".NewError(\"mismatched message type: got %q, want %q\", got, want)") g.P(" }") g.P(" return opts.Unmarshal(src.GetValue(), dst)") g.P("}") @@ -608,7 +608,7 @@ func genMessageKnownFunctions(g *protogen.GeneratedFile, f *fileInfo, m *message g.P("// It reports false for a nil FieldMask.") g.P("func (x *FieldMask) IsValid(m ", protoPackage.Ident("Message"), ") bool {") g.P(" paths := x.GetPaths()") - g.P(" return numValidPaths(m, paths) == len(paths)") + g.P(" return x != nil && numValidPaths(m, paths) == len(paths)") g.P("}") g.P() diff --git a/types/known/anypb/any.pb.go b/types/known/anypb/any.pb.go index 061a9eeb..47bc5555 100644 --- a/types/known/anypb/any.pb.go +++ b/types/known/anypb/any.pb.go @@ -194,13 +194,13 @@ func MarshalFrom(dst *Any, src proto.Message, opts proto.MarshalOptions) error { // // If no options are specified, call src.UnmarshalTo instead. func UnmarshalTo(src *Any, dst proto.Message, opts proto.UnmarshalOptions) error { - if src.GetTypeUrl() == "" { - return protoimpl.X.NewError("invalid empty type URL") + if src == nil { + return protoimpl.X.NewError("invalid nil source message") } if !src.MessageIs(dst) { got := dst.ProtoReflect().Descriptor().FullName() want := src.MessageName() - return protoimpl.X.NewError("mismatching message types: got %q, want %q", got, want) + return protoimpl.X.NewError("mismatched message type: got %q, want %q", got, want) } return opts.Unmarshal(src.GetValue(), dst) } diff --git a/types/known/fieldmaskpb/field_mask.pb.go b/types/known/fieldmaskpb/field_mask.pb.go index ae1be0e0..da32aa54 100644 --- a/types/known/fieldmaskpb/field_mask.pb.go +++ b/types/known/fieldmaskpb/field_mask.pb.go @@ -307,7 +307,7 @@ func Intersect(mx *FieldMask, my *FieldMask, ms ...*FieldMask) *FieldMask { // It reports false for a nil FieldMask. func (x *FieldMask) IsValid(m proto.Message) bool { paths := x.GetPaths() - return numValidPaths(m, paths) == len(paths) + return x != nil && numValidPaths(m, paths) == len(paths) } // Append appends a list of paths to the mask and verifies that each one