{"record":{"id":"9a5e2d6a31d1437b","repo":"apache/beam","slug":"not-expected-to-access-dofn-finishbundlecontext-from","errorCode":null,"errorMessage":"Not expected to access DoFn.FinishBundleContext from @ProcessElement","messagePattern":"Not expected to access DoFn\\.FinishBundleContext 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":294,"sourceCode":"              return processContext.pane();\n            }\n\n            @Override\n            public PipelineOptions pipelineOptions() {\n              return getPipelineOptions();\n            }\n\n            @Override\n            public DoFn<InputT, OutputT>.StartBundleContext startBundleContext(\n                DoFn<InputT, OutputT> doFn) {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access DoFn.StartBundleContext from @ProcessElement\");\n            }\n\n            @Override\n            public DoFn<InputT, OutputT>.FinishBundleContext finishBundleContext(\n                DoFn<InputT, OutputT> doFn) {\n              throw new UnsupportedOperationException(\n                  \"Not expected to access DoFn.FinishBundleContext from @ProcessElement\");\n            }\n\n            @Override\n            public DoFn<InputT, OutputT>.ProcessContext processContext(DoFn<InputT, OutputT> doFn) {\n              return processContext;\n            }\n\n            @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            }","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java#L276-L312","documentation":"DoFnTester's ProcessContext cannot supply a FinishBundleContext: FinishBundleContext is only meaningful inside @FinishBundle. If a @ProcessElement method requests it as a parameter, the tester throws UnsupportedOperationException.","triggerScenarios":"A @ProcessElement method with a DoFn.FinishBundleContext parameter executed via DoFnTester.processElement.","commonSituations":"DoFns that emit per-bundle aggregates from within processElement using finish bundle context; legacy code ported from other frameworks being unit tested with DoFnTester.","solutions":["Move FinishBundleContext usage into a @FinishBundle method; do not request it in @ProcessElement","Collect per-element outputs in instance state and emit in @FinishBundle instead","Use TestPipeline integration tests where full lifecycle contexts are provided correctly"],"exampleFix":"// before\n@ProcessElement public void processElement(ProcessContext c, FinishBundleContext fbc) {...}\n// after\n@ProcessElement public void processElement(ProcessContext c) {...}\n@FinishBundle public void finishBundle(FinishBundleContext c) {...}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// FinishBundleContext is only valid in @FinishBundle methods\nboolean inFinishBundle = method.isAnnotationPresent(FinishBundle.class);","tryCatchPattern":"try {\n  tester.processElement();\n} catch (UnsupportedOperationException e) {\n  // FinishBundleContext requested in @ProcessElement\n}","preventionTips":["Emit per-bundle results only from @FinishBundle","Keep @ProcessElement signatures limited to ProcessContext/@Element"],"tags":["apache-beam","java","testing","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-14T16:17:12.679Z"}