{"record":{"id":"5b9ed95452f16236","repo":"apache/beam","slug":"cannot-call-getpipelineoptions-in-a-null-context","errorCode":null,"errorMessage":"cannot call getPipelineOptions() in a null context","messagePattern":"cannot call getPipelineOptions\\(\\) 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":32,"sourceCode":" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.beam.sdk.state;\n\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  }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateContexts.java#L14-L50","documentation":"StateContexts.NULL_CONTEXT is a placeholder StateContext used when no real context is bound (e.g. state accessed outside a pipeline execution context). Calling getPipelineOptions() on it always throws this IllegalArgumentException — it is a deliberate sentinel guard, and the faulty input is the context-less call site, not any argument.","triggerScenarios":"Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateContexts.java:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the getPipelineOptions() call to where a real StateContext exists (inside a DoFn's @Setup/@ProcessElement with state).","Pass the pipeline options through explicitly (e.g. via a constructor or side input) instead of reading them from a null context.","Check that state is being accessed through StateContexts.withCancellation/combined contexts rather than the bare NULL_CONTEXT."],"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"}