apache/beam · error · UnsupportedOperationException

State unsupported in

Error message

State unsupported in %s

What it means

The stub DoFnInvoker throws UnsupportedOperationException when state(stateId, alwaysFetched) is called, because state access is only meaningful during lifecycle phases that carry a runner-provided StateContext. getErrorContext() identifies the DoFn involved.

Solutions

  1. Build the invoker with DoFnInvokers.tryInvokeFor so state() is implemented
  2. Access State only inside methods whose signature includes the state parameter (e.g. @ProcessElement)
  3. Verify the runner supports @StateId state cells for this DoFn

Example fix

// before
new DoFnInvoker.BaseDoFnInvoker<T, O>(){}.state("myState", false); // throws
// after
DoFnInvokers.tryInvokeFor(fn).state("myState", false);
Defensive patterns

Strategy: validation

Validate before calling

if (fn.getClass().isAnnotationPresent(StateId.class)) {
  ensureInvokerSupportsState(invoker);
}

Type guard

boolean supportsState(DoFnInvoker<?, ?> i) {
  return !(i instanceof DoFnInvoker.BaseDoFnInvoker);
}

Try / catch

try {
  State state = invoker.state(stateId, false);
} catch (UnsupportedOperationException e) {
  throw new IllegalStateException("State access unsupported by this invoker/runner", e);
}

Prevention

When it happens

Trigger: Calling state(...) on an invoker instance that inherits the base class implementation instead of a generated/reflective invoker with state support.

Common situations: Using @StateId state with a runner or test harness that did not wire state support; accessing state outside processElement/bundle phases; hand-built invokers in unit tests.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java:464

          String.format("OnTimerContext unsupported in %s", getErrorContext()));
    }

    @Override
    public DoFn<InputT, OutputT>.OnWindowExpirationContext onWindowExpirationContext(
        DoFn<InputT, OutputT> doFn) {
      throw new UnsupportedOperationException(
          String.format("OnWindowExpirationContext unsupported in %s", getErrorContext()));
    }

    @Override
    public State state(String stateId, boolean alwaysFetched) {
      throw new UnsupportedOperationException(
          String.format("State unsupported in %s", getErrorContext()));
    }

    @Override
    public Timer timer(String timerId) {
      throw new UnsupportedOperationException(
          String.format("Timer unsupported in %s", getErrorContext()));
    }

    @Override
    public RestrictionTracker<?, ?> restrictionTracker() {
      throw new UnsupportedOperationException(
          String.format("RestrictionTracker unsupported in %s", getErrorContext()));
    }

    @Override
    public Object watermarkEstimatorState() {
      throw new UnsupportedOperationException(
          String.format("WatermarkEstimatorState unsupported in %s", getErrorContext()));
    }

    @Override
    public WatermarkEstimator<?> watermarkEstimator() {
      throw new UnsupportedOperationException(

View on GitHub (pinned to 12126d8942)