apache/beam · error · UnsupportedOperationException
Element unsupported in
Error message
Element unsupported in ${context} What it means
The default BaseArgumentProvider.element() throws UnsupportedOperationException because element access is only meaningful inside an element-processing context. The message is templated with getErrorContext() naming the unsupported context, indicating the ArgumentProvider installed for this invocation does not carry an element.
Solutions
- Move element() access into the @ProcessElement method where a ProcessContext is available
- In @StartBundle/@FinishBundle, remove element() access or restructure to use the bundle context
- In tests, override element() in your ArgumentProvider stub
- Ensure the runner installs an element-aware ArgumentProvider for @ProcessElement invocations
Example fix
// before
@StartBundle
public void startBundle(StartBundleContext ctx) {
process(c.element()); // throws
}
// after
@ProcessElement
public void processElement(ProcessContext c) {
process(c.element());
} Defensive patterns
Strategy: type-guard
Validate before calling
// Before invoking a DoFn method that uses element():
boolean isProcessElement = method.isAnnotationPresent(DoFn.ProcessElement.class);
if (!isProcessElement) {
throw new IllegalStateException("element() only valid in @ProcessElement context");
} Type guard
static boolean hasElementSupport(DoFnInvoker.ArgumentProvider<?, ?> p, DoFn<?, ?> fn) {
try { p.element(fn); return true; }
catch (UnsupportedOperationException e) { return false; }
} Try / catch
try {
InputT el = args.element(doFn);
} catch (UnsupportedOperationException e) {
throw new IllegalStateException("element() is only available in @ProcessElement context", e);
} Prevention
- Never call element() from @StartBundle/@FinishBundle
- Keep element access in @ProcessElement signatures (c.element())
- Use generated invokers rather than instantiating BaseArgumentProvider directly
- Write runner code to install an element-aware ArgumentProvider
When it happens
Trigger: Invoking a DoFn method whose ArgumentProvider lacks element support — e.g. calling context.element() from @StartBundle/@FinishBundle, or a test invoker built on the default BaseArgumentProvider.
Common situations: Calling element() in bundle lifecycle callbacks instead of @ProcessElement; hand-written test harnesses using BaseArgumentProvider directly; custom runners that forgot to install a ProcessContext-backed ArgumentProvider for @ProcessElement.
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 fire timestamp outside of @OnTimer method.
- Cannot access key as parameter outside of @OnTimer method.
- Cannot access timerId as parameter outside of @OnTimer…
- CausedByDrain unsupported in
- FinishBundleContext unsupported in
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/ef5a971fb1a64b44.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnInvoker.java:312
*/
String timerId(DoFn<InputT, OutputT> doFn);
}
/**
* This {@link ArgumentProvider} throws {@link UnsupportedOperationException} for all parameters.
*/
@Internal
abstract class BaseArgumentProvider<InputT, OutputT>
implements ArgumentProvider<InputT, OutputT> {
@Override
public DoFn<InputT, OutputT>.ProcessContext processContext(DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
String.format("ProcessContext unsupported in %s", getErrorContext()));
}
@Override
public InputT element(DoFn<InputT, OutputT> doFn) {
throw new UnsupportedOperationException(
String.format("Element unsupported in %s", getErrorContext()));
}
@Override
public @Nullable Object key() {
throw new UnsupportedOperationException(
"Cannot access key as parameter outside of @OnTimer method.");
}
@Override
public @Nullable Object sideInput(String tagId) {
throw new UnsupportedOperationException(
String.format("SideInput unsupported in %s", getErrorContext()));
}
@Override
public TimerMap timerFamily(String tagId) {
throw new UnsupportedOperationException(View on GitHub (pinned to 12126d8942)