{"record":{"id":"a4d9a8e830dfd5bd","repo":"apache/beam","slug":"accumulators-not-supported-in-this-context","errorCode":null,"errorMessage":"Accumulators not supported in this context","messagePattern":"Accumulators not supported in this context","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/translate/SingleValueContext.java","lineNumber":71,"sourceCode":"  /**\n   * Replace the stored value with given one.\n   *\n   * @param elem the element to store\n   */\n  @Override\n  public void collect(T elem) {\n    value = elem;\n  }\n\n  @Override\n  public Context asContext() {\n    return this;\n  }\n\n  @Override\n  public Counter getCounter(String name) {\n    if (wrap == null) {\n      throw new UnsupportedOperationException(\"Accumulators not supported in this context\");\n    }\n    return wrap.getCounter(name);\n  }\n\n  @Override\n  public Histogram getHistogram(String name) {\n    if (wrap == null) {\n      throw new UnsupportedOperationException(\"Accumulators not supported in this context\");\n    }\n    return wrap.getHistogram(name);\n  }\n\n  @Override\n  public Timer getTimer(String name) {\n    if (wrap == null) {\n      throw new UnsupportedOperationException(\"Accumulators not supported in this context\");\n    }\n    return wrap.getTimer(name);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/translate/SingleValueContext.java#L53-L89","documentation":"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.","triggerScenarios":"Calling context.getCounter(name) inside a e.g. ElementsToOne / single-value functor whose SingleValueContext was constructed with a null wrap.","commonSituations":"User code in a reduce/ElementsToOne transformation trying to increment a counter although the context only carries a single element and no accumulator facility.","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"],"exampleFix":"// before\ncontext.getCounter(\"my-counter\").increment();\n// after\n// accumulate in the value instead of a counter\nvalue.add(1); // or drop metrics in this context","handlingStrategy":"type-guard","validationCode":"if (context instanceof SingleValueContext && !((SingleValueContext) context).hasAccumulators()) { /* skip counters */ }","typeGuard":"boolean supportsAccumulators(Context ctx) { return !(ctx instanceof SingleValueContext) || ((SingleValueContext) ctx).hasAccumulators(); }","tryCatchPattern":"try { context.getCounter(\"c\").increment(); } catch (UnsupportedOperationException e) { /* metrics unavailable in this context */ }","preventionTips":["Don't use counters/histograms/timers inside ElementsToOne-style functors","Aggregate metrics into the returned value instead","Check context capabilities before metric calls"],"tags":["unsupported-operation","accumulators","beam","euphoria"],"backgroundTag":"operation-not-supported","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}