apache/beam · error
base map cannot be nil
Error message
base map cannot be nil
What it means
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.
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.
Example fix
// before
var base map[string]string
reflectx.UpdateMap(base, updates) // panics
// after
base := map[string]string{}
reflectx.UpdateMap(base, updates) Defensive patterns
Strategy: validation
Validate before calling
if base == nil {
return errors.New("base map must be initialized before UpdateMap")
} Try / catch
func safeUpdateMap(base, updates any) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("UpdateMap failed: %v", r)
}
}()
reflectx.UpdateMap(base, updates)
return nil
} Prevention
- Always initialize maps with make or a composite literal before merging.
- Never assign a map field without constructing it first.
When it happens
Trigger: Calling reflectx.UpdateMap(nil, someMap), or Update on a registry whose base map field was never initialized.
Common situations: 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).
Related errors
- bad decode
- bad encode
- bad return type for
- beam.RegisterSchemaProvider: unsupported type kind for…
- cannot convert field
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/fe3959725b767c53.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/util.go:73
return ret.Interface()
case reflect.Array, reflect.Chan, reflect.Interface, reflect.Func, reflect.Invalid:
panic(fmt.Sprintf("unsupported type for clone: %v", t))
default:
return v
}
}
// UpdateMap merges two maps of type map[K]*V, with the second overwriting values
// into the first (and mutating it). If the overwriting value is nil, the key is
// deleted.
func UpdateMap(base, updates any) {
if updates == nil {
return // ok: nop
}
if base == nil {
panic("base map cannot be nil")
}
m := reflect.ValueOf(base)
o := reflect.ValueOf(updates)
if o.Type().Kind() != reflect.Map || m.Type() != o.Type() {
panic(fmt.Sprintf("invalid types for map update: %v != %v", m.Type(), o.Type()))
}
keys := o.MapKeys()
for _, key := range keys {
val := o.MapIndex(key)
if val.IsNil() {
m.SetMapIndex(key, reflect.Value{}) // delete
} else {
m.SetMapIndex(key, val)
}
}View on GitHub (pinned to 12126d8942)