{"record":{"id":"fe3959725b767c53","repo":"apache/beam","slug":"base-map-cannot-be-nil","errorCode":null,"errorMessage":"base map cannot be nil","messagePattern":"base map cannot be nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/util.go","lineNumber":73,"sourceCode":"\t\treturn ret.Interface()\n\n\tcase reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:\n\t\tpanic(fmt.Sprintf(\"unsupported type for clone: %v\", t))\n\n\tdefault:\n\t\treturn v\n\t}\n}\n\n// UpdateMap merges two maps of type map[K]*V, with the second overwriting values\n// into the first (and mutating it). If the overwriting value is nil, the key is\n// deleted.\nfunc UpdateMap(base, updates any) {\n\tif updates == nil {\n\t\treturn // ok: nop\n\t}\n\tif base == nil {\n\t\tpanic(\"base map cannot be nil\")\n\t}\n\n\tm := reflect.ValueOf(base)\n\to := reflect.ValueOf(updates)\n\n\tif o.Type().Kind() != reflect.Map || m.Type() != o.Type() {\n\t\tpanic(fmt.Sprintf(\"invalid types for map update: %v != %v\", m.Type(), o.Type()))\n\t}\n\n\tkeys := o.MapKeys()\n\tfor _, key := range keys {\n\t\tval := o.MapIndex(key)\n\t\tif val.IsNil() {\n\t\t\tm.SetMapIndex(key, reflect.Value{}) // delete\n\t\t} else {\n\t\t\tm.SetMapIndex(key, val)\n\t\t}\n\t}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/util.go#L55-L91","documentation":"reflectx.UpdateMap merges an updates map into a base map in place. A nil base map is a programming error — there is no destination to write into — so the library panics. A nil updates map is explicitly allowed as a no-op.","triggerScenarios":"Calling reflectx.UpdateMap(nil, someMap), or Update on a registry whose base map field was never initialized.","commonSituations":"Merging option/config maps (TestMergeMaps-style usage) where the base map variable is nil because it was declared but never initialized with make(map[T]V).","solutions":["Initialize the base map before updating: base := map[K]V{}.","Check base != nil before calling UpdateMap.","Fix the struct/registry field so the base map is constructed at init time."],"exampleFix":"// before\nvar base map[string]string\nreflectx.UpdateMap(base, updates) // panics\n// after\nbase := map[string]string{}\nreflectx.UpdateMap(base, updates)","handlingStrategy":"validation","validationCode":"if base == nil {\n    return errors.New(\"base map must be initialized before UpdateMap\")\n}","typeGuard":null,"tryCatchPattern":"func safeUpdateMap(base, updates any) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"UpdateMap failed: %v\", r)\n        }\n    }()\n    reflectx.UpdateMap(base, updates)\n    return nil\n}","preventionTips":["Always initialize maps with make or a composite literal before merging.","Never assign a map field without constructing it first."],"tags":["go","reflection","nil-map"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}