{"record":{"id":"1e112e67edeeb5dc","repo":"apache/beam","slug":"state-unsupported-in-s","errorCode":null,"errorMessage":"State unsupported in %s","messagePattern":"State unsupported in (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java","lineNumber":464,"sourceCode":"          String.format(\"OnTimerContext unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public DoFn<InputT, OutputT>.OnWindowExpirationContext onWindowExpirationContext(\n        DoFn<InputT, OutputT> doFn) {\n      throw new UnsupportedOperationException(\n          String.format(\"OnWindowExpirationContext unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public State state(String stateId, boolean alwaysFetched) {\n      throw new UnsupportedOperationException(\n          String.format(\"State unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public Timer timer(String timerId) {\n      throw new UnsupportedOperationException(\n          String.format(\"Timer unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public RestrictionTracker<?, ?> restrictionTracker() {\n      throw new UnsupportedOperationException(\n          String.format(\"RestrictionTracker unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public Object watermarkEstimatorState() {\n      throw new UnsupportedOperationException(\n          String.format(\"WatermarkEstimatorState unsupported in %s\", getErrorContext()));\n    }\n\n    @Override\n    public WatermarkEstimator<?> watermarkEstimator() {\n      throw new UnsupportedOperationException(","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java#L446-L482","documentation":"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.","triggerScenarios":"Calling state(...) on an invoker instance that inherits the base class implementation instead of a generated/reflective invoker with state support.","commonSituations":"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.","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"],"exampleFix":"// before\nnew DoFnInvoker.BaseDoFnInvoker<T, O>(){}.state(\"myState\", false); // throws\n// after\nDoFnInvokers.tryInvokeFor(fn).state(\"myState\", false);","handlingStrategy":"validation","validationCode":"if (fn.getClass().isAnnotationPresent(StateId.class)) {\n  ensureInvokerSupportsState(invoker);\n}","typeGuard":"boolean supportsState(DoFnInvoker<?, ?> i) {\n  return !(i instanceof DoFnInvoker.BaseDoFnInvoker);\n}","tryCatchPattern":"try {\n  State state = invoker.state(stateId, false);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalStateException(\"State access unsupported by this invoker/runner\", e);\n}","preventionTips":["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"],"tags":["java","apache-beam","unsupported-operation","state"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}