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
- Build the invoker with DoFnInvokers.tryInvokeFor so state() is implemented
- Access State only inside methods whose signature includes the state parameter (e.g. @ProcessElement)
- 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
- Consume state through the method's @StateId-parameterized State<T> argument
- Verify runner state support (e.g. not all runners support all state types)
- Test DoFns with state using TestPipeline, not hand-built invokers
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
- BoundedWindow unsupported in
- Cannot access fire timestamp outside of @OnTimer method.
- Cannot access OnTimerContext outside of @OnTimer methods.
- Cannot access OnWindowExpirationContext outside of…
- Cannot access state in non-window observing context.
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)