apache/iceberg · error · UnsupportedOperationException

Counter is not supported.

Error message

Counter is not supported.

What it means

This deprecated default method MetricsContext.counter(String, Class<T>, Unit) is a stub that throws UnsupportedOperationException('Counter is not supported.'). Contexts not supporting typed counters inherit this throw. It exists so the interface can deprecate the method without forcing implementations to change.

Source

Thrown at api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java:117

     */
    default Unit unit() {
      return Unit.UNDEFINED;
    }
  }

  /**
   * Get a named counter of a specific type. Metric implementations may impose restrictions on what
   * types are supported for specific counters.
   *
   * @param name name of the metric
   * @param type numeric type of the counter value
   * @param unit the unit designation of the metric
   * @return a counter implementation
   * @deprecated will be removed in 2.0.0, use {@link MetricsContext#counter(String, Unit)} instead.
   */
  @Deprecated
  default <T extends Number> Counter<T> counter(String name, Class<T> type, Unit unit) {
    throw new UnsupportedOperationException("Counter is not supported.");
  }

  /**
   * Get a named counter.
   *
   * @param name The name of the counter
   * @param unit The unit designation of the counter
   * @return a {@link org.apache.iceberg.metrics.Counter} implementation
   */
  default org.apache.iceberg.metrics.Counter counter(String name, Unit unit) {
    throw new UnsupportedOperationException("Counter is not supported.");
  }

  /**
   * Get a named counter using {@link Unit#COUNT}
   *
   * @param name The name of the counter
   * @return a {@link org.apache.iceberg.metrics.Counter} implementation

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Migrate to the non-deprecated MetricsContext.counter(String, Unit)
  2. Use DefaultMetricsContext which implements counters
  3. Implement this method in custom MetricsContext classes
  4. Suppress usage via IDE inspection and refactor call sites

Example fix

// before
Counter<Long> c = ctx.counter("scan", Long.class, Unit.COUNT);
// after
org.apache.iceberg.metrics.Counter c = ctx.counter("scan", Unit.COUNT);
Defensive patterns

Strategy: fallback

Try / catch

try { deprecated call } catch (UnsupportedOperationException e) { use counter(name, unit) }

Prevention

When it happens

Trigger: Calling the deprecated 3-arg counter(name, type, unit) on a MetricsContext implementation that does not override it (e.g. anonymous or minimal implementations), or on contexts whose counter() default delegates here.

Common situations: Legacy code still using the deprecated signature after the 2.0.0 deprecation; custom MetricsContext implementations compiled before the newer counter(name, unit) method existed.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/95e0479e6c32dfde. Report an issue: GitHub.