{"record":{"id":"ee6c4b81c52ab534","repo":"apache/iceberg","slug":"counter-for-type-s-is-not-supported","errorCode":null,"errorMessage":"Counter for type %s is not supported","messagePattern":"Counter for type (.+?) is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/metrics/DefaultMetricsContext.java","lineNumber":41,"sourceCode":"/** A default {@link MetricsContext} implementation that uses native Java counters/timers. */\npublic class DefaultMetricsContext implements MetricsContext {\n  private static final int DEFAULT_HISTOGRAM_RESERVOIR_SIZE = 10_000;\n\n  /**\n   * @deprecated will be removed in 2.0.0, use {@link org.apache.iceberg.metrics.Counter} instead.\n   */\n  @Override\n  @Deprecated\n  @SuppressWarnings(\"unchecked\")\n  public <T extends Number> Counter<T> counter(String name, Class<T> type, Unit unit) {\n    if (Integer.class.equals(type)) {\n      return (Counter<T>) new DefaultCounter(unit).asIntCounter();\n    }\n\n    if (Long.class.equals(type)) {\n      return (Counter<T>) new DefaultCounter(unit).asLongCounter();\n    }\n    throw new IllegalArgumentException(\n        String.format(\"Counter for type %s is not supported\", type.getName()));\n  }\n\n  @Override\n  public Timer timer(String name, TimeUnit unit) {\n    return new DefaultTimer(unit);\n  }\n\n  @Override\n  public org.apache.iceberg.metrics.Counter counter(String name, Unit unit) {\n    return new DefaultCounter(unit);\n  }\n\n  @Override\n  public Histogram histogram(String name) {\n    return new FixedReservoirHistogram(DEFAULT_HISTOGRAM_RESERVOIR_SIZE);\n  }\n}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/metrics/DefaultMetricsContext.java#L23-L59","documentation":"DefaultMetricsContext.counter(name, type) only supports Integer and Long counter types; any other Number subtype (Double, Float, etc.) triggers this IllegalArgumentException with the unsupported type's name. It enforces the metric types Iceberg counters support.","triggerScenarios":"Calling DefaultMetricsContext.counter(name, Double.class, unit) or with any Class<T extends Number> other than Integer.class or Long.class.","commonSituations":"Developers assuming generic numeric counters are supported; refactoring code from other metrics libraries that allow double counters; copying a counter declaration with a wrong type parameter.","solutions":["Use Integer.class or Long.class as the counter type","For non-integer metrics use a Histogram or a different metrics mechanism","Wrap the call and surface a clear configuration error if the type comes from user config"],"exampleFix":"// before\nCounter<Double> c = metrics.counter(\"ratio\", Double.class, Unit.COUNT);\n// after\nCounter<Long> c = metrics.counter(\"ratio\", Long.class, Unit.COUNT);","handlingStrategy":"validation","validationCode":"if (!Integer.class.equals(type) && !Long.class.equals(type)) { fix; }","typeGuard":"boolean ok(Class<?> t) { return t == Integer.class || t == Long.class; }","tryCatchPattern":"try { ... } catch (IllegalArgumentException e) { fallback to Long counter }","preventionTips":["Stick to Integer/Long counter types","Use Histogram for other distributions"],"tags":["java","metrics","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}