{"record":{"id":"024fda58e4ecb605","repo":"apache/iceberg","slug":"timer-is-not-supported","errorCode":null,"errorMessage":"Timer is not supported.","messagePattern":"Timer is not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java","lineNumber":149,"sourceCode":"  /**\n   * Get a named counter using {@link Unit#COUNT}\n   *\n   * @param name The name of the counter\n   * @return a {@link org.apache.iceberg.metrics.Counter} implementation\n   */\n  default org.apache.iceberg.metrics.Counter counter(String name) {\n    return counter(name, Unit.COUNT);\n  }\n\n  /**\n   * Get a named timer.\n   *\n   * @param name name of the metric\n   * @param unit the time unit designation of the metric\n   * @return a timer implementation\n   */\n  default Timer timer(String name, TimeUnit unit) {\n    throw new UnsupportedOperationException(\"Timer is not supported.\");\n  }\n\n  default Histogram histogram(String name) {\n    throw new UnsupportedOperationException(\"Histogram is not supported.\");\n  }\n\n  /**\n   * Utility method for producing no metrics.\n   *\n   * @return a non-recording metrics context\n   */\n  static MetricsContext nullMetrics() {\n    return new MetricsContext() {\n\n      @Override\n      public Timer timer(String name, TimeUnit unit) {\n        return Timer.NOOP;\n      }","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java#L131-L167","documentation":"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.","triggerScenarios":"Calling timer(name, unit) on a MetricsContext implementation that doesn't override it, then starting/recording the timer.","commonSituations":"Custom or minimal MetricsContext implementations used in tests or embedded contexts; runtime context swaps where the new context lacks timer support.","solutions":["Use DefaultMetricsContext which provides DefaultTimer","Override timer(String, TimeUnit) in your custom MetricsContext","If timing is unsupported by design, return a NOOP timer instead","Guard timer creation behind a capability check"],"exampleFix":"// before\nTimer t = ctx.timer(\"plan\", TimeUnit.NANOSECONDS); // throws\n// after\nTimer t = new DefaultMetricsContext().timer(\"plan\", TimeUnit.NANOSECONDS);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { timer } catch (UnsupportedOperationException e) { NOOP timer }","preventionTips":["Override timer() in custom contexts","Use DefaultMetricsContext"],"tags":["java","metrics","timer","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}