apache/beam · error · UnsupportedOperationException
Accumulators not supported in this context
Error message
Accumulators not supported in this context
What it means
SingleValueContext.getCounter throws UnsupportedOperationException when the context was created without a wrapped accumulator context (wrap == null). Single-value element contexts have no accumulator backing, so counters are unavailable in that scope.
Solutions
- Remove counter usage from the single-value functor body
- Use a context/windowing variant that provides accumulators (wrap != null), e.g. via a translation path that supplies AccumulatorProvider
- Accumulate results into the returned single value instead of counters
- Guard with a check on context capabilities before calling getCounter
Example fix
// before
context.getCounter("my-counter").increment();
// after
// accumulate in the value instead of a counter
value.add(1); // or drop metrics in this context Defensive patterns
Strategy: type-guard
Validate before calling
if (context instanceof SingleValueContext && !((SingleValueContext) context).hasAccumulators()) { /* skip counters */ } Type guard
boolean supportsAccumulators(Context ctx) { return !(ctx instanceof SingleValueContext) || ((SingleValueContext) ctx).hasAccumulators(); } Try / catch
try { context.getCounter("c").increment(); } catch (UnsupportedOperationException e) { /* metrics unavailable in this context */ } Prevention
- Don't use counters/histograms/timers inside ElementsToOne-style functors
- Aggregate metrics into the returned value instead
- Check context capabilities before metric calls
When it happens
Trigger: Calling context.getCounter(name) inside a e.g. ElementsToOne / single-value functor whose SingleValueContext was constructed with a null wrap.
Common situations: User code in a reduce/ElementsToOne transformation trying to increment a counter although the context only carries a single element and no accumulator facility.
Related errors
- Cannot translate Euphoria 'Join' operator to Beam…
- Cannot translate Euphoria 'Join' operator to Beam…
- BeamAccumulatorProvider doesn't support getCounter(String…
- BeamAccumulatorProvider doesn't support getHistogram(String…
- BeamAccumulatorProvider doesn't support getTimer(String…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a4d9a8e830dfd5bd.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/translate/SingleValueContext.java:71
/**
* Replace the stored value with given one.
*
* @param elem the element to store
*/
@Override
public void collect(T elem) {
value = elem;
}
@Override
public Context asContext() {
return this;
}
@Override
public Counter getCounter(String name) {
if (wrap == null) {
throw new UnsupportedOperationException("Accumulators not supported in this context");
}
return wrap.getCounter(name);
}
@Override
public Histogram getHistogram(String name) {
if (wrap == null) {
throw new UnsupportedOperationException("Accumulators not supported in this context");
}
return wrap.getHistogram(name);
}
@Override
public Timer getTimer(String name) {
if (wrap == null) {
throw new UnsupportedOperationException("Accumulators not supported in this context");
}
return wrap.getTimer(name);View on GitHub (pinned to 12126d8942)