apache/beam · error

window must not be nil

Error message

window must not be nil

What it means

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.

Source

Thrown at sdks/go/pkg/beam/core/graph/coder/coder.go:416

}

// IsW returns true iff the coder is for a WindowedValue.
func IsW(c *Coder) bool {
	return c.Kind == WindowedValue
}

// NewPI returns a PaneInfo coder
func NewPI() *Coder {
	return &Coder{Kind: PaneInfo, T: typex.New(typex.PaneInfoType)}
}

// NewW returns a WindowedValue coder for the window of elements.
func NewW(c *Coder, w *WindowCoder) *Coder {
	if c == nil {
		panic("coder must not be nil")
	}
	if w == nil {
		panic("window must not be nil")
	}

	return &Coder{
		Kind:       WindowedValue,
		T:          typex.NewW(c.T),
		Window:     w,
		Components: []*Coder{c},
	}
}

// NewPW returns a ParamWindowedValue coder for the window of elements.
func NewPW(c *Coder, w *WindowCoder) *Coder {
	if c == nil {
		panic("coder must not be nil")
	}
	if w == nil {
		panic("window must not be nil")
	}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass an explicit window coder such as coder.NewGlobalWindow() or coder.NewIntervalWindowCoder().
  2. Check the origin of the *WindowCoder for nil-returning error paths and propagate the error.
  3. Initialize window coders in a shared helper that never returns nil.

Example fix

// before
wc := coder.NewW(c, nil) // panics
// after
wc := coder.NewW(c, coder.NewGlobalWindow())
Defensive patterns

Strategy: validation

Validate before calling

if w == nil {
    w = coder.NewGlobalWindow() // or return an error
}
wc := coder.NewW(c, w)

Type guard

func hasWindowCoder(w *coder.WindowCoder) bool { return w != nil }

Try / catch

func newWSafe(c *coder.Coder, w *coder.WindowCoder) (wc *coder.Coder, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("NewW failed: %v", r)
        }
    }()
    return coder.NewW(c, w), nil
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom windowing pipelines where a window coder was assumed but never created; test code copying coder setups and dropping the window argument.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b2bbc4bf63266d24. Report an issue: GitHub.