{"record":{"id":"a81dbe27cbf9c3b2","repo":"apache/beam","slug":"invalid-types-for-map-update-v-v","errorCode":null,"errorMessage":"invalid types for map update: %v != %v","messagePattern":"invalid types for map update: (.+?) != (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/util.go","lineNumber":80,"sourceCode":"\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}\n}\n","sourceCodeStart":62,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/util.go#L62-L93","documentation":"reflectx.UpdateMap requires both arguments to be maps of exactly the same reflect.Type so keys and values can be copied directly. It panics when updates is not a map at all, or when the base and updates map types differ (e.g. map[string]int vs map[string]string).","triggerScenarios":"Calling UpdateMap(base, updates) where updates is not a map, or where base and updates have different map types (key or value type mismatch).","commonSituations":"Merging option maps built with different value types, or accidentally passing a non-map (e.g. a struct or slice) as updates in registry/Update helper usage.","solutions":["Use identical map types for base and updates (same key and value types).","Verify the updates argument is a map before calling.","Convert values to the base map's type and rebuild the updates map."],"exampleFix":"// before\nreflectx.UpdateMap(map[string]int{}, map[string]string{\"a\": \"1\"}) // panics\n// after\nreflectx.UpdateMap(map[string]int{}, map[string]int{\"a\": 1})","handlingStrategy":"type-guard","validationCode":"mb, mu := reflect.TypeOf(base), reflect.TypeOf(updates)\nif mb == nil || mb.Kind() != reflect.Map || mu == nil || mu.Kind() != reflect.Map || mb != mu {\n    return fmt.Errorf(\"both args must be same map type, got %v and %v\", mb, mu)\n}","typeGuard":"func sameMapType(base, updates any) bool {\n    tb, tu := reflect.TypeOf(base), reflect.TypeOf(updates)\n    return tb != nil && tu != nil && tb.Kind() == reflect.Map && tb == tu\n}","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":["Declare base and updates with identical map types.","Convert heterogeneous option maps to a common type before merging."],"tags":["go","reflection","type-mismatch"],"backgroundTag":"type-mismatch","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"}