{"record":{"id":"b2bbc4bf63266d24","repo":"apache/beam","slug":"window-must-not-be-nil","errorCode":null,"errorMessage":"window must not be nil","messagePattern":"window must not be nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/coder.go","lineNumber":416,"sourceCode":"}\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}\n\tif w == nil {\n\t\tpanic(\"window must not be nil\")\n\t}","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/coder.go#L398-L434","documentation":"NewW in sdks/go/pkg/beam/core/graph/coder/coder.go panics with \"window must not be nil\" when the WindowCoder argument for a WindowedValue coder is nil. A WindowedValue coder must record how windows themselves are encoded, so a nil window coder is invalid and triggers a fail-fast panic instead of producing an unmarshalable coder.","triggerScenarios":"Calling coder.NewW(c, nil), typically when the *WindowCoder variable was never assigned or a constructor returning (*WindowCoder, error) returned nil and the error was ignored.","commonSituations":"Custom windowing pipelines where a window coder was assumed but never created; test code copying coder setups and dropping the window argument.","solutions":["Pass an explicit window coder such as coder.NewGlobalWindow() or coder.NewIntervalWindowCoder().","Check the origin of the *WindowCoder for nil-returning error paths and propagate the error.","Initialize window coders in a shared helper that never returns nil."],"exampleFix":"// before\nwc := coder.NewW(c, nil) // panics\n// after\nwc := coder.NewW(c, coder.NewGlobalWindow())","handlingStrategy":"validation","validationCode":"if w == nil {\n    w = coder.NewGlobalWindow() // or return an error\n}\nwc := coder.NewW(c, w)","typeGuard":"func hasWindowCoder(w *coder.WindowCoder) bool { return w != 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":["Default to coder.NewGlobalWindow() when no windowing strategy is configured.","Handle errors from window-coder constructors instead of passing nil through.","Store window coders in package-level helpers so call sites get valid defaults."],"tags":["go","apache-beam","coder","nil-check","windowing"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}