apache/beam · error · UnsupportedOperationException
Not expected to access TimeDomain from @ProcessElement
Error message
Not expected to access TimeDomain from @ProcessElement
What it means
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.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/DoFnTester.java:327
public Object key() {
throw new UnsupportedOperationException(
"Cannot access key as parameter outside of @OnTimer method.");
}
@Override
public Instant timestamp(DoFn<InputT, OutputT> doFn) {
return processContext.timestamp();
}
@Override
public String timerId(DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
"Cannot access timerId as parameter outside of @OnTimer method.");
}
@Override
public TimeDomain timeDomain(DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
"Not expected to access TimeDomain from @ProcessElement");
}
@Override
public OutputReceiver<OutputT> outputReceiver(DoFn<InputT, OutputT> doFn) {
return DoFnOutputReceivers.windowedReceiver(processContext, builderSupplier, null);
}
@Override
public MultiOutputReceiver taggedOutputReceiver(DoFn<InputT, OutputT> doFn) {
return DoFnOutputReceivers.windowedMultiReceiver(
processContext, builderSupplier, null);
}
@Override
public Object restriction() {
throw new UnsupportedOperationException(
"Not expected to access Restriction from a regular DoFn in DoFnTester");View on GitHub (pinned to 12126d8942)
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
Example fix
// before
@ProcessElement public void process(ProcessContext c, TimeDomain domain) {...}
// after
@ProcessElement public void process(ProcessContext c) {...}
@OnTimer("myTimer") public void onTimer(TimeDomain domain) {...} Defensive patterns
Strategy: type-guard
Type guard
// TimeDomain only injectable in timer callbacks boolean inTimerCallback = method.isAnnotationPresent(OnTimer.class);
Try / catch
try {
tester.processElement();
} catch (UnsupportedOperationException e) {
// TimeDomain requested in @ProcessElement
} Prevention
- Request TimeDomain only in @OnTimer methods
- Structure helpers so time-domain logic lives exclusively in timer callbacks
When it happens
Trigger: Declaring a TimeDomain parameter in a @ProcessElement method and executing it with DoFnTester.
Common situations: DoFns branching on event-time vs processing-time timers whose helper methods are also invoked from processElement; tests of such DoFns 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
- Cannot access timerId as parameter outside of @OnTimer metho
- Not expected to access DoFn.StartBundleContext from @Process
- Not expected to access DoFn.FinishBundleContext from @Proces
- Cannot access key as parameter outside of @OnTimer method.
- 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/b50aa3034440cda8.
Report an issue: GitHub.