apache/beam · error · UnsupportedOperationException

%s is for internal use only and does not support case dispat

Error message

%s is for internal use only and does not support case dispatch

What it means

CombiningWithContextStateSpec.match(Cases) is unsupported: this spec is for internal use only and does not participate in the StateSpec case-dispatch (visitor/Cases) mechanism. It always throws UnsupportedOperationException.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java:558

    private @Nullable Coder<AccumT> accumCoder;
    private final CombineFnWithContext<InputT, AccumT, OutputT> combineFn;

    private CombiningWithContextStateSpec(
        @Nullable Coder<AccumT> accumCoder,
        CombineFnWithContext<InputT, AccumT, OutputT> combineFn) {
      this.combineFn = combineFn;
      this.accumCoder = accumCoder;
    }

    @Override
    public CombiningState<InputT, AccumT, OutputT> bind(String id, StateBinder visitor) {
      return visitor.bindCombiningWithContext(id, this, accumCoder, combineFn);
    }

    @Override
    public <ResultT> ResultT match(Cases<ResultT> cases) {
      throw new UnsupportedOperationException(
          String.format(
              "%s is for internal use only and does not support case dispatch",
              getClass().getSimpleName()));
    }

    @SuppressWarnings("unchecked")
    @Override
    public void offerCoders(Coder[] coders) {
      if (this.accumCoder == null && coders[2] != null) {
        this.accumCoder = (Coder<AccumT>) coders[2];
      }
    }

    @Override
    public void finishSpecifying() {
      if (accumCoder == null) {
        throw new IllegalStateException(
            "Unable to infer a coder for"

View on GitHub (pinned to 12126d8942)

Solutions

  1. Do not dispatch on this spec with Cases; use the StateBinder visitor path (bind()) instead.
  2. If you need the combineFn/coder, access the spec's fields directly rather than via match().
  3. Treat CombiningWithContextState as internal and route handling through bindCombiningWithContext.
Defensive patterns

Strategy: type-guard

Validate before calling

if (spec instanceof CombiningWithContextStateSpec) { /* handle via bind/visitor, never .match() */ }

Type guard

boolean supportsCaseDispatch(StateSpec<?, ?> s) { return !(s instanceof CombiningWithContextStateSpec); }

Try / catch

try {
  return spec.match(cases);
} catch (UnsupportedOperationException e) {
  // route CombiningWithContext specs through StateBinder.bindCombiningWithContext instead
  return handleWithContextBinder(spec);
}

Prevention

When it happens

Trigger: Calling .match(cases) on a CombiningWithContextStateSpec obtained from StateSpecs.combiningWithContext(...), or runner/framework code that generically dispatches over all StateSpecs with Cases.

Common situations: Runner authors writing generic state-spec handling code; users reflecting over state cells and trying to pattern-match spec types.

Related errors


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