{"record":{"id":"0ad6fcdf754fc935","repo":"apache/beam","slug":"coder-must-not-be-nil","errorCode":null,"errorMessage":"coder must not be nil","messagePattern":"coder must not be nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/coder.go","lineNumber":413,"sourceCode":"// NewIntervalWindowCoder returns a new IntervalWindow coder using the built-in scheme.\nfunc NewIntervalWindowCoder() *Coder {\n\treturn &Coder{Kind: IW, T: typex.New(reflect.TypeOf((*struct{ Start, End int64 })(nil)).Elem())}\n}\n\n// IsW returns true iff the coder is for a WindowedValue.\nfunc IsW(c *Coder) bool {\n\treturn c.Kind == WindowedValue\n}\n\n// NewPI returns a PaneInfo coder\nfunc NewPI() *Coder {\n\treturn &Coder{Kind: PaneInfo, T: typex.New(typex.PaneInfoType)}\n}\n\n// NewW returns a WindowedValue coder for the window of elements.\nfunc NewW(c *Coder, w *WindowCoder) *Coder {\n\tif c == nil {\n\t\tpanic(\"coder must not be nil\")\n\t}\n\tif w == nil {\n\t\tpanic(\"window must not be nil\")\n\t}\n\n\treturn &Coder{\n\t\tKind:       WindowedValue,\n\t\tT:          typex.NewW(c.T),\n\t\tWindow:     w,\n\t\tComponents: []*Coder{c},\n\t}\n}\n\n// NewPW returns a ParamWindowedValue coder for the window of elements.\nfunc NewPW(c *Coder, w *WindowCoder) *Coder {\n\tif c == nil {\n\t\tpanic(\"coder must not be nil\")\n\t}","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/coder.go#L395-L431","documentation":"NewW in sdks/go/pkg/beam/core/graph/coder/coder.go panics with \"coder must not be nil\" when the element coder passed for a WindowedValue coder is nil. A WindowedValue coder wraps an element coder plus a window coder, so a nil element coder would produce a broken composite. The constructor treats nil as a caller programming bug and fails fast.","triggerScenarios":"Calling coder.NewW(nil, w) directly, or passing a coder variable that was never initialized — e.g. a registry/map lookup that returned nil with its error ignored.","commonSituations":"Test helpers (TestCoder_String, TestCoders) and pipeline graph builders composing coders from maps where the element-coder key was missing; refactors changing initialization order.","solutions":["Build the element coder before NewW, e.g. c := coder.NewJ(T); wc := coder.NewW(c, coder.NewGlobalWindow()).","Fix the producer of the nil coder: handle error/empty returns from any (coder, err) lookup.","Add an explicit nil check at the call site to fail closer to the origin."],"exampleFix":"// before\nvar c *coder.Coder\nwc := coder.NewW(c, coder.NewGlobalWindow()) // panics\n// after\nc := coder.NewJ(reflect.TypeOf(\"\"))\nwc := coder.NewW(c, coder.NewGlobalWindow())","handlingStrategy":"validation","validationCode":"if c == nil {\n    return nil, errors.New(\"element coder must be initialized before NewW\")\n}\nwc := coder.NewW(c, coder.NewGlobalWindow())","typeGuard":"func isCoderReady(c *coder.Coder) bool { return c != nil && c.T != nil }","tryCatchPattern":"func newWSafe(c *coder.Coder, w *coder.WindowCoder) (wc *coder.Coder, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"NewW failed: %v\", r)\n        }\n    }()\n    return coder.NewW(c, w), nil\n}","preventionTips":["Always construct element coders via constructors (NewJ, NewI, NewKV) rather than zero values.","Check (coder, err) returns; never pass a possibly-nil coder onward.","Initialize coder graphs in a fixed order: element coder, then window coder, then wrappers."],"tags":["go","apache-beam","coder","nil-check","panic"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}