{"record":{"id":"9608a5955243c34e","repo":"apache/beam","slug":"cannot-access-timerid-as-parameter-outside-of-ontimer-method","errorCode":null,"errorMessage":"Cannot access timerId as parameter outside of @OnTimer method.","messagePattern":"Cannot access timerId as parameter outside of @OnTimer method\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java","lineNumber":321,"sourceCode":"            @Override\n            public InputT element(DoFn<InputT, OutputT> doFn) {\n              return processContext.element();\n            }\n\n            @Override\n            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);","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java#L303-L339","documentation":"The timerId context parameter is only available inside @OnTimer callbacks. DoFnTester's ProcessContext throws UnsupportedOperationException when a @ProcessElement method requests timerId, since no timer is firing during element processing.","triggerScenarios":"Declaring a String timerId parameter (annotated as TimerId) in a @ProcessElement method run through DoFnTester.","commonSituations":"Copy-pasting @OnTimer signatures into @ProcessElement; DoFns sharing a helper that takes timerId and is also called from processElement.","solutions":["Move the timerId parameter into the @OnTimer method only","Pass the timer id as a constant/field (it's a compile-time known id) rather than a context parameter in processElement","Refactor shared logic to not depend on timer identity outside timer callbacks"],"exampleFix":"// before\n@ProcessElement public void process(ProcessContext c, @TimerId String id) {...}\n// after\nprivate static final String TIMER_ID = \"myTimer\";\n@OnTimer(TIMER_ID) public void onTimer(@TimerId String id) {...}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// TimerId only injectable in @OnTimer callbacks\nboolean inOnTimer = method.isAnnotationPresent(OnTimer.class);","tryCatchPattern":"try {\n  tester.processElement();\n} catch (UnsupportedOperationException e) {\n  // @TimerId parameter used in @ProcessElement\n}","preventionTips":["Timer ids are compile-time constants; reference the constant instead of a context parameter","Keep @OnTimer-specific parameters out of @ProcessElement signatures"],"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"}