apache/beam · error · UnsupportedOperationException
Not expected to access DoFn.FinishBundleContext from @Proces
Error message
Not expected to access DoFn.FinishBundleContext from @ProcessElement
What it means
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.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java:294
return processContext.pane();
}
@Override
public PipelineOptions pipelineOptions() {
return getPipelineOptions();
}
@Override
public DoFn<InputT, OutputT>.StartBundleContext startBundleContext(
DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
"Not expected to access DoFn.StartBundleContext from @ProcessElement");
}
@Override
public DoFn<InputT, OutputT>.FinishBundleContext finishBundleContext(
DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
"Not expected to access DoFn.FinishBundleContext from @ProcessElement");
}
@Override
public DoFn<InputT, OutputT>.ProcessContext processContext(DoFn<InputT, OutputT> doFn) {
return processContext;
}
@Override
public InputT element(DoFn<InputT, OutputT> doFn) {
return processContext.element();
}
@Override
public Object key() {
throw new UnsupportedOperationException(
"Cannot access key as parameter outside of @OnTimer method.");
}View on GitHub (pinned to 12126d8942)
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
Example fix
// before
@ProcessElement public void processElement(ProcessContext c, FinishBundleContext fbc) {...}
// after
@ProcessElement public void processElement(ProcessContext c) {...}
@FinishBundle public void finishBundle(FinishBundleContext c) {...} Defensive patterns
Strategy: type-guard
Type guard
// FinishBundleContext is only valid in @FinishBundle methods boolean inFinishBundle = method.isAnnotationPresent(FinishBundle.class);
Try / catch
try {
tester.processElement();
} catch (UnsupportedOperationException e) {
// FinishBundleContext requested in @ProcessElement
} Prevention
- Emit per-bundle results only from @FinishBundle
- Keep @ProcessElement signatures limited to ProcessContext/@Element
When it happens
Trigger: A @ProcessElement method with a DoFn.FinishBundleContext parameter executed via DoFnTester.processElement.
Common situations: DoFns that emit per-bundle aggregates from within processElement using finish bundle context; legacy code ported from other frameworks being unit tested with DoFnTester.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Not expected to access DoFn.StartBundleContext from @Process
- Cannot access key as parameter outside of @OnTimer method.
- Cannot access timerId as parameter outside of @OnTimer metho
- Not expected to access TimeDomain from @ProcessElement
- Not expected to access Restriction from a regular DoFn in Do
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9a5e2d6a31d1437b.
Report an issue: GitHub.