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

  1. Restrict the TimeDomain parameter to @OnTimer methods; hard-code or branch elsewhere via other means
  2. Refactor helpers that need TimeDomain so they're only called from timer callbacks
  3. 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

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


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b50aa3034440cda8. Report an issue: GitHub.