apache/beam · error
unexpected number of parameters in method
Error message
unexpected number of parameters in method %v. got: %v, want number in range: 0 to 1. Check that the signature conforms to the expected signature for %v.
What it means
The CreateWatermarkEstimator method accepts 0 or 1 parameters (at most one, e.g. an initial estimator state). Beam rejects the DoFn when the method declares more than one parameter, telling you to match the expected signature.
Solutions
- Reduce CreateWatermarkEstimator to at most one parameter: either no parameters or exactly the initial state type InitialWatermarkEstimatorState() returns.
- Move any extra configuration into the DoFn's fields rather than method parameters.
- If you want a stateful estimator, also define InitialWatermarkEstimatorState and WatermarkEstimatorState methods consistently.
Example fix
// before
func (fn *f) CreateWatermarkEstimator(state StateT, cfg Cfg) *myEstimator {...}
// after
func (fn *f) CreateWatermarkEstimator(state StateT) *myEstimator {...} Defensive patterns
Strategy: validation
Validate before calling
func wmCreatorArity(fn interface{}) error {
m, ok := reflect.TypeOf(fn).MethodByName("CreateWatermarkEstimator")
if ok && m.Type.NumIn() > 2 { // receiver + params
return fmt.Errorf("CreateWatermarkEstimator has %d params, want 0 or 1", m.Type.NumIn()-1)
}
return nil
} Prevention
- CreateWatermarkEstimator takes either nothing or exactly the initial state; inject config via struct fields.
- Copy signatures from the sdf package docs/examples rather than writing them freehand.
When it happens
Trigger: Defining CreateWatermarkEstimator with two or more parameters, e.g. CreateWatermarkEstimator(state StateT, config ConfigT) int64.
Common situations: Passing extra context/config arguments by mistake; misunderstanding which arguments Beam injects into creator methods.
Related errors
- unexpected number of return values in method
- capacity of cache cannot be negative, got
- could not unmarshal iterable coder from
- could not unmarshal nullable coder from
- could not unmarshal sharded_key coder from
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/efdf8c9ba115240a.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:1183
processElementName, pos)
return false, errors.SetTopLevelMsgf(err, "Method %v has an sdf.WatermarkEstimator parameter at index %v, "+
"but is not part of a watermark estimating DoFn. sdf.WatermarkEstimator is invalid in %v in "+
"non-watermark estimating DoFns.",
processElementName, pos, processElementName)
}
return isWatermarkEstimating, nil
}
// validateWatermarkSig validates that all watermark related functions are valid
func validateWatermarkSig(fn *Fn, numMainIn int) error {
returnNum := 1 // TODO(BEAM-3301): Enable optional error params in SDF methods.
watermarkEstimatorT := reflect.TypeOf((*sdf.WatermarkEstimator)(nil)).Elem()
method := fn.methods[createWatermarkEstimatorName]
if len(method.Param) > 1 {
err := errors.Errorf("unexpected number of params in method %v. got: %v, want number in range: 0 to 1",
createWatermarkEstimatorName, len(method.Param))
return errors.SetTopLevelMsgf(err, "unexpected number of parameters in method %v. "+
"got: %v, want number in range: 0 to 1. Check that the signature conforms to the expected signature for %v.",
createWatermarkEstimatorName, len(method.Param), createWatermarkEstimatorName)
} else if len(method.Param) == 1 {
err := validateStatefulWatermarkSig(fn, numMainIn)
if err != nil {
return err
}
} else {
if _, ok := fn.methods[initialWatermarkEstimatorStateName]; ok {
err := errors.Errorf("stateful watermark estimation method %v is present, "+
"but CreateWatermarkEstimator doesn't take in a state parameter.", initialWatermarkEstimatorStateName)
return err
}
if _, ok := fn.methods[watermarkEstimatorStateName]; ok {
err := errors.Errorf("stateful watermark estimation method %v is present, "+
"but CreateWatermarkEstimator doesn't take in a state parameter.", watermarkEstimatorStateName)View on GitHub (pinned to 12126d8942)