Comment 4 for bug 1841105

Revision history for this message
John A Meinel (jameinel) wrote :

The code in question is:
// visitField invokes ctx.structVisitor(val) if v is a struct and returns back
// the visitor's result. On the other hand, if val is a slice or a map,
// visitField invoke specialized functions that support iterating such types.
func visitField(ctx *visitorContext, val interface{}) bool {
        typ := reflect.TypeOf(val)
        v := reflect.ValueOf(val)

        // De-reference pointers
        if v.Kind() == reflect.Ptr {
                v = v.Elem()
                if v.Kind() == reflect.Invalid {
                        return false
                }
                typ = v.Type()
        }

        switch typ.Kind() {
        case reflect.Struct:
                return ctx.structVisitor(ctx, v, typ)
        case reflect.Map:
                return visitFieldsInMap(ctx, v)
        case reflect.Slice:
                return visitFieldsInSlice(ctx, v)
        }

        // v is not a struct or something we can iterate to reach a struct
        return false
}

But the docs:
https://golang.org/pkg/reflect/#TypeOf

say that reflect.TypeOf(nil) => nil, thus the later call to typ.Kind() is an invalid call.

I don't know what value in the bundle would point to nil, but regardless we can have code that is defensive against nil values.