{"record":{"id":"b50aa3034440cda8","repo":"apache/beam","slug":"not-expected-to-access-timedomain-from-processelement","errorCode":null,"errorMessage":"Not expected to access TimeDomain from @ProcessElement","messagePattern":"Not expected to access TimeDomain from @ProcessElement","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java","lineNumber":327,"sourceCode":"            public Object key() {\n              throw new UnsupportedOperationException(\n                  \"Cannot access key as parameter outside of @OnTimer method.\");\n            }\n\n            @Override\n            public Instant timestamp(DoFn<InputT, OutputT> doFn) {\n              return processContext.timestamp();\n            }\n\n            @Override\n            public String timerId(DoFn<InputT, OutputT> doFn) {\n              throw new UnsupportedOperationException(\n                  \"Cannot access timerId as parameter outside of @OnTimer method.\");\n            }\n\n            @Override\n            public TimeDomain timeDomain(DoFn<InputT, OutputT> doFn) {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access TimeDomain from @ProcessElement\");\n            }\n\n            @Override\n            public OutputReceiver<OutputT> outputReceiver(DoFn<InputT, OutputT> doFn) {\n              return DoFnOutputReceivers.windowedReceiver(processContext, builderSupplier, null);\n            }\n\n            @Override\n            public MultiOutputReceiver taggedOutputReceiver(DoFn<InputT, OutputT> doFn) {\n              return DoFnOutputReceivers.windowedMultiReceiver(\n                  processContext, builderSupplier, null);\n            }\n\n            @Override\n            public Object restriction() {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access Restriction from a regular DoFn in DoFnTester\");","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java#L309-L345","documentation":"TimeDomain is only injectable in timer-related callbacks (@OnTimer, @GetWatermark callbacks). DoFnTester's ProcessContext cannot provide a TimeDomain during @ProcessElement and throws UnsupportedOperationException if one is requested.","triggerScenarios":"Declaring a TimeDomain parameter in a @ProcessElement method and executing it with DoFnTester.","commonSituations":"DoFns branching on event-time vs processing-time timers whose helper methods are also invoked from processElement; tests of such DoFns with DoFnTester.","solutions":["Restrict the TimeDomain parameter to @OnTimer methods; hard-code or branch elsewhere via other means","Refactor helpers that need TimeDomain so they're only called from timer callbacks","Use TestPipeline-based tests if timer semantics need coverage"],"exampleFix":"// before\n@ProcessElement public void process(ProcessContext c, TimeDomain domain) {...}\n// after\n@ProcessElement public void process(ProcessContext c) {...}\n@OnTimer(\"myTimer\") public void onTimer(TimeDomain domain) {...}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// TimeDomain only injectable in timer callbacks\nboolean inTimerCallback = method.isAnnotationPresent(OnTimer.class);","tryCatchPattern":"try {\n  tester.processElement();\n} catch (UnsupportedOperationException e) {\n  // TimeDomain requested in @ProcessElement\n}","preventionTips":["Request TimeDomain only in @OnTimer methods","Structure helpers so time-domain logic lives exclusively in timer callbacks"],"tags":["apache-beam","java","testing","dofn","timers"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}