apache/iceberg · error · UnsupportedOperationException

Timer is not supported.

Error message

Timer is not supported.

What it means

MetricsContext.timer(String, TimeUnit) is a default stub throwing UnsupportedOperationException('Timer is not supported.'). Contexts that don't support timers inherit this; real timing requires an implementation such as DefaultMetricsContext's DefaultTimer.

Source

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

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

  /**
   * Get a named timer.
   *
   * @param name name of the metric
   * @param unit the time unit designation of the metric
   * @return a timer implementation
   */
  default Timer timer(String name, TimeUnit unit) {
    throw new UnsupportedOperationException("Timer is not supported.");
  }

  default Histogram histogram(String name) {
    throw new UnsupportedOperationException("Histogram is not supported.");
  }

  /**
   * Utility method for producing no metrics.
   *
   * @return a non-recording metrics context
   */
  static MetricsContext nullMetrics() {
    return new MetricsContext() {

      @Override
      public Timer timer(String name, TimeUnit unit) {
        return Timer.NOOP;
      }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Use DefaultMetricsContext which provides DefaultTimer
  2. Override timer(String, TimeUnit) in your custom MetricsContext
  3. If timing is unsupported by design, return a NOOP timer instead
  4. Guard timer creation behind a capability check

Example fix

// before
Timer t = ctx.timer("plan", TimeUnit.NANOSECONDS); // throws
// after
Timer t = new DefaultMetricsContext().timer("plan", TimeUnit.NANOSECONDS);
Defensive patterns

Strategy: fallback

Try / catch

try { timer } catch (UnsupportedOperationException e) { NOOP timer }

Prevention

When it happens

Trigger: Calling timer(name, unit) on a MetricsContext implementation that doesn't override it, then starting/recording the timer.

Common situations: Custom or minimal MetricsContext implementations used in tests or embedded contexts; runtime context swaps where the new context lacks timer support.

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


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