{"record":{"id":"95e0479e6c32dfde","repo":"apache/iceberg","slug":"counter-is-not-supported","errorCode":null,"errorMessage":"Counter is not supported.","messagePattern":"Counter is not supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java","lineNumber":117,"sourceCode":"     */\n    default Unit unit() {\n      return Unit.UNDEFINED;\n    }\n  }\n\n  /**\n   * Get a named counter of a specific type. Metric implementations may impose restrictions on what\n   * types are supported for specific counters.\n   *\n   * @param name name of the metric\n   * @param type numeric type of the counter value\n   * @param unit the unit designation of the metric\n   * @return a counter implementation\n   * @deprecated will be removed in 2.0.0, use {@link MetricsContext#counter(String, Unit)} instead.\n   */\n  @Deprecated\n  default <T extends Number> Counter<T> counter(String name, Class<T> type, Unit unit) {\n    throw new UnsupportedOperationException(\"Counter is not supported.\");\n  }\n\n  /**\n   * Get a named counter.\n   *\n   * @param name The name of the counter\n   * @param unit The unit designation of the counter\n   * @return a {@link org.apache.iceberg.metrics.Counter} implementation\n   */\n  default org.apache.iceberg.metrics.Counter counter(String name, Unit unit) {\n    throw new UnsupportedOperationException(\"Counter is not supported.\");\n  }\n\n  /**\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","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/MetricsContext.java#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Migrate to the non-deprecated MetricsContext.counter(String, Unit)","Use DefaultMetricsContext which implements counters","Implement this method in custom MetricsContext classes","Suppress usage via IDE inspection and refactor call sites"],"exampleFix":"// before\nCounter<Long> c = ctx.counter(\"scan\", Long.class, Unit.COUNT);\n// after\norg.apache.iceberg.metrics.Counter c = ctx.counter(\"scan\", Unit.COUNT);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { deprecated call } catch (UnsupportedOperationException e) { use counter(name, unit) }","preventionTips":["Stop using deprecated overloads","Implement defaults in custom contexts"],"tags":["java","metrics","deprecated","unsupported-operation"],"backgroundTag":"deprecated-api-usage","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"}