{"record":{"id":"1cd02f9503b8a7fc","repo":"apache/iceberg","slug":"unsupported-counter-s","errorCode":null,"errorMessage":"Unsupported counter: '%s'","messagePattern":"Unsupported counter: '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopMetricsContext.java","lineNumber":85,"sourceCode":"  @SuppressWarnings(\"unchecked\")\n  public <T extends Number> Counter<T> counter(String name, Class<T> type, Unit unit) {\n    switch (name) {\n      case READ_BYTES:\n        ValidationException.check(type == Long.class, \"'%s' requires Long type\", READ_BYTES);\n        return (Counter<T>) longCounter(statistics()::incrementBytesRead);\n      case READ_OPERATIONS:\n        ValidationException.check(\n            type == Integer.class, \"'%s' requires Integer type\", READ_OPERATIONS);\n        return (Counter<T>) integerCounter(statistics()::incrementReadOps);\n      case WRITE_BYTES:\n        ValidationException.check(type == Long.class, \"'%s' requires Long type\", WRITE_BYTES);\n        return (Counter<T>) longCounter(statistics()::incrementBytesWritten);\n      case WRITE_OPERATIONS:\n        ValidationException.check(\n            type == Integer.class, \"'%s' requires Integer type\", WRITE_OPERATIONS);\n        return (Counter<T>) integerCounter(statistics()::incrementWriteOps);\n      default:\n        throw new IllegalArgumentException(String.format(\"Unsupported counter: '%s'\", name));\n    }\n  }\n\n  private Counter<Long> longCounter(Consumer<Long> consumer) {\n    return new Counter<Long>() {\n      @Override\n      public void increment() {\n        increment(1L);\n      }\n\n      @Override\n      public void increment(Long amount) {\n        consumer.accept(amount);\n      }\n    };\n  }\n\n  private Counter<Integer> integerCounter(Consumer<Integer> consumer) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopMetricsContext.java#L67-L103","documentation":"HadoopMetricsContext.counter(String, Class) only supports WRITE_BYTES and WRITE_OPERATIONS counters and type-checks each (WRITE_OPERATIONS requires Integer). Any other Counter.Name, or a wrong type parameter, throws IllegalArgumentException.","triggerScenarios":"Calling counter(name, type) with a counter name other than WRITE_BYTES/WRITE_OPERATIONS, or WRITE_OPERATIONS with a type other than Integer.class (e.g. Long.class).","commonSituations":"Custom metrics integrations requesting a counter name defined elsewhere (e.g. from another metrics context); refactors that widened Integer to Long; passing generic Counter.Name constants not present in this Hadoop context.","solutions":["Only request WRITE_BYTES or WRITE_OPERATIONS from HadoopMetricsContext","Use Integer.class as the type for WRITE_OPERATIONS","Route other counter names to the appropriate MetricsContext implementation"],"exampleFix":"// before\nCounter<Long> c = metrics.counter(Counter.Name.WRITE_OPERATIONS, Long.class); // throws\n// after\nCounter<Integer> c = metrics.counter(Counter.Name.WRITE_OPERATIONS, Integer.class);","handlingStrategy":"validation","validationCode":"Set<Counter.Name> SUPPORTED = Set.of(Counter.Name.WRITE_BYTES, Counter.Name.WRITE_OPERATIONS);\nif (!SUPPORTED.contains(name)) {\n  throw new IllegalArgumentException(\"HadoopMetricsContext only supports WRITE_BYTES/WRITE_OPERATIONS\");\n}\nif (name == Counter.Name.WRITE_OPERATIONS && type != Integer.class) {\n  throw new IllegalArgumentException(\"WRITE_OPERATIONS requires Integer.class\");\n}","typeGuard":null,"tryCatchPattern":"try { return ctx.counter(name, type); }\ncatch (IllegalArgumentException e) { LOG.warn(\"Counter {} unsupported by Hadoop context\", name); return Counter.noop(); }","preventionTips":["Whitelist only WRITE_BYTES and WRITE_OPERATIONS for this context","Use Integer.class for WRITE_OPERATIONS","Keep a central mapping of counter names to the contexts that support them"],"tags":["hadoop","metrics","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}