{"record":{"id":"059f59b69dff3bc5","repo":"apache/beam","slug":"cannot-access-sideinput-in-non-window-observing-context","errorCode":null,"errorMessage":"Cannot access sideInput in non-window observing context.","messagePattern":"Cannot access sideInput in non-window observing context\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnApiDoFnRunner.java","lineNumber":1972,"sourceCode":"\n    @Override\n    public CausedByDrain causedByDrain(DoFn<InputT, OutputT> doFn) {\n      return currentElement.causedByDrain();\n    }\n  }\n\n  /** Provides base arguments for a {@link DoFnInvoker} for a non-window observing method. */\n  private abstract class NonWindowObservingProcessBundleContextBase\n      extends ProcessBundleContextBase {\n    @Override\n    public BoundedWindow window() {\n      throw new UnsupportedOperationException(\n          \"Cannot access window in non-window observing context.\");\n    }\n\n    @Override\n    public Object sideInput(String tagId) {\n      throw new UnsupportedOperationException(\n          \"Cannot access sideInput in non-window observing context.\");\n    }\n\n    @Override\n    public <T> T sideInput(PCollectionView<T> view) {\n      throw new UnsupportedOperationException(\n          \"Cannot access sideInput in non-window observing context.\");\n    }\n\n    @Override\n    public State state(String stateId, boolean alwaysFetched) {\n      throw new UnsupportedOperationException(\n          \"Cannot access state in non-window observing context.\");\n    }\n\n    @Override\n    public org.apache.beam.sdk.state.Timer timer(String timerId) {\n      throw new UnsupportedOperationException(","sourceCodeStart":1954,"sourceCodeEnd":1990,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnApiDoFnRunner.java#L1954-L1990","documentation":"NonWindowObservingProcessBundleContextBase.sideInput(String tagId) throws UnsupportedOperationException because side inputs require a bound window to resolve a view, and this context serves a method that was not declared window-observing. The harness therefore refuses to resolve side inputs in this context.","triggerScenarios":"Calling ProcessContext.sideInput(tagId) (string overload) from a @ProcessElement method without a BoundedWindow parameter, or from @StartBundle/@FinishBundle, where no window is available to index the side input view.","commonSituations":"Reading a side input in a non-windowed DoFn after refactoring; using the tag-based sideInput API introduced with newer Beam versions from lifecycle methods; forgetting the BoundedWindow parameter after migrating code.","solutions":["Add a BoundedWindow parameter to the @ProcessElement signature so the window-observing context (which implements sideInput) is used.","Use the view-based c.sideInput(PCollectionView) only inside window-observing @ProcessElement methods.","If the side input is window-independent, read it via a different mechanism (e.g., pass the data as the main input or a broadcast/readied view computed outside the DoFn)."],"exampleFix":"// before\n@ProcessElement\npublic void processElement(ProcessContext c) {\n  Object v = c.sideInput(\"myTag\"); // throws\n}\n\n// after\n@ProcessElement\npublic void processElement(ProcessContext c, BoundedWindow window) {\n  MyView v = c.sideInput(myView);\n}","handlingStrategy":"validation","validationCode":"// Resolve side inputs only in window-observing @ProcessElement methods:\nboolean canReadSideInput = Arrays.stream(dofn.getClass().getDeclaredMethods())\n    .filter(m -> m.isAnnotationPresent(ProcessElement.class))\n    .anyMatch(m -> Arrays.stream(m.getParameterTypes()).anyMatch(BoundedWindow.class::isAssignableFrom));","typeGuard":"BoundedWindow requireWindow(DoFn.ProcessContext ctx) {\n  BoundedWindow w = ctx instanceof FnApiDoFnRunner.ProcessBundleContextBase\n      ? null : null;\n  return w; // null => non-window-observing context, side input unavailable\n}","tryCatchPattern":"try {\n  V v = c.sideInput(view);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalStateException(\"sideInput requires a window-observing @ProcessElement (add BoundedWindow param)\", e);\n}","preventionTips":["Add BoundedWindow to @ProcessElement before using any sideInput API.","Never read side inputs in @StartBundle/@FinishBundle.","Prefer the sideInput(PCollectionView) overload over raw tag ids and keep signatures consistent."],"tags":["java","beam","apache-beam","side-input","dofn"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}