apache/beam · error · UnsupportedOperationException
Not supported.
Error message
Not supported.
What it means
SingleValueCollector.asContext always throws UnsupportedOperationException; the collector wraps a single element directly and intentionally has no Context view, because the underlying functor never needs one.
Solutions
- Do not call asContext() on single-value collectors; use the collector's direct methods (getCounter, getHistogram, collect)
- Branch on collector type before calling asContext()
- Restructure code so context-based access happens only in element collectors
Example fix
// before
Context ctx = collector.asContext();
// after
if (collector instanceof ElementCollector) { Context ctx = ((ElementCollector) collector).asContext(); } Defensive patterns
Strategy: type-guard
Validate before calling
if (collector instanceof SingleValueCollector) { /* don't call asContext() */ } Type guard
Optional<Context> tryAsContext(Collector<?> c) { return (c instanceof SingleValueCollector) ? Optional.empty() : Optional.of(((ElementCollector<?>) c).asContext()); } Try / catch
try { ctx = collector.asContext(); } catch (UnsupportedOperationException e) { /* use direct collector methods instead */ } Prevention
- Only request Context from element collectors
- Branch on collector type in generic utility code
- Prefer collector.getCounter/getHistogram over context access
When it happens
Trigger: Calling collector.asContext() on a SingleValueCollector, e.g. generic code that treats every collector uniformly and requests a context for accumulator/timer operations.
Common situations: Framework-style user code iterating collectors of different kinds; someone attempting to use context-based (windowed/element-context) APIs in a single-value collection.
Related errors
- Accumulators not supported in this context
- Cannot access OnTimerContext outside of @OnTimer methods.
- Cannot access OnWindowExpirationContext outside of…
- Cannot determine context class
- Cannot translate Euphoria 'Join' operator to Beam…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/8a9a5996033a9767.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/translate/collector/SingleValueCollector.java:65
public SingleValueCollector(AccumulatorProvider accumulators, @Nullable String operatorName) {
this.accumulators = accumulators;
this.operatorName = operatorName;
}
public T get() {
return elem;
}
@Override
public void collect(T elem) {
this.elem = elem;
}
@Override
public Context asContext() {
// this is not needed, the underlying functor does not have access to this
throw new UnsupportedOperationException("Not supported.");
}
@Override
public Counter getCounter(String name) {
return accumulators.getCounter(requireNonNull(operatorName, UNSUPPORTED), name);
}
@Override
public Histogram getHistogram(String name) {
return accumulators.getHistogram(requireNonNull(operatorName, UNSUPPORTED), name);
}
@Override
public Timer getTimer(String name) {
return accumulators.getTimer(name);
}
}
View on GitHub (pinned to 12126d8942)