{"record":{"id":"d2acf22856316fc2","repo":"apache/beam","slug":"cannot-call-sideinput-in-a-null-context","errorCode":null,"errorMessage":"cannot call sideInput() in a null context","messagePattern":"cannot call sideInput\\(\\) in a null context","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateContexts.java","lineNumber":37,"sourceCode":"\nimport org.apache.beam.sdk.annotations.Internal;\nimport org.apache.beam.sdk.options.PipelineOptions;\nimport org.apache.beam.sdk.transforms.windowing.BoundedWindow;\nimport org.apache.beam.sdk.values.PCollectionView;\n\n/** <b><i>For internal use only; no backwards-compatibility guarantees.</i></b> */\n@Internal\npublic class StateContexts {\n  private static final StateContext<BoundedWindow> NULL_CONTEXT =\n      new StateContext<BoundedWindow>() {\n        @Override\n        public PipelineOptions getPipelineOptions() {\n          throw new IllegalArgumentException(\"cannot call getPipelineOptions() in a null context\");\n        }\n\n        @Override\n        public <T> T sideInput(PCollectionView<T> view) {\n          throw new IllegalArgumentException(\"cannot call sideInput() in a null context\");\n        }\n\n        @Override\n        public BoundedWindow window() {\n          throw new IllegalArgumentException(\"cannot call window() in a null context\");\n        }\n      };\n\n  /** Returns a fake {@link StateContext}. */\n  @SuppressWarnings(\"unchecked\")\n  public static <W extends BoundedWindow> StateContext<W> nullContext() {\n    return (StateContext<W>) NULL_CONTEXT;\n  }\n\n  public static <W extends BoundedWindow> StateContext<W> windowOnlyContext(W window) {\n    return new WindowOnlyContext<>(window);\n  }\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateContexts.java#L19-L55","documentation":"The NULL_CONTEXT StateContext in StateContexts throws unconditionally from sideInput(PCollectionView): side inputs can only be resolved against a live pipeline execution window, and this context exists only to satisfy the interface when no context is available. The faulty input is a side-input lookup attempted outside real pipeline execution.","triggerScenarios":"Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateContexts.java:37 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Access side inputs inside a DoFn's process element method where the ProcessContext supplies a real window.","If you need the view's data outside execution, materialize it via a runner-supported mechanism (e.g. pass as pipeline option or a side input to a transform) rather than calling sideInput() directly.","Ensure you are not unit-testing context objects created via StateContexts.nullContext(); construct a real context instead."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}