{"record":{"id":"9a82be6890c19585","repo":"apache/hadoop","slug":"bad-fs-counter-name","errorCode":null,"errorMessage":"bad fs counter name","messagePattern":"bad fs counter name","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/counters/FileSystemCounterGroup.java","lineNumber":186,"sourceCode":"    if (ours != null) {\n      ours.setValue(counter.getValue());\n    }\n  }\n\n  @Override\n  public C addCounter(String name, String displayName, long value) {\n    C counter = findCounter(name);\n    if (counter != null) {\n      counter.setValue(value);\n    }\n    return counter;\n  }\n\n  // Parse generic counter name into [scheme, key]\n  private String[] parseCounterName(String counterName) {\n    int schemeEnd = counterName.indexOf('_');\n    if (schemeEnd < 0) {\n      throw new IllegalArgumentException(\"bad fs counter name\");\n    }\n    return new String[]{counterName.substring(0, schemeEnd),\n                        counterName.substring(schemeEnd + 1)};\n  }\n\n  @Override\n  public C findCounter(String counterName, String displayName) {\n    return findCounter(counterName);\n  }\n\n  @Override\n  public C findCounter(String counterName, boolean create) {\n    try {\n      String[] pair = parseCounterName(counterName);\n      return findCounter(pair[0], FileSystemCounter.valueOf(pair[1]));\n    }\n    catch (Exception e) {\n      if (create) throw new IllegalArgumentException(e);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/counters/FileSystemCounterGroup.java#L168-L204","documentation":"FileSystemCounterGroup stores the per-scheme filesystem counters (\"File System Counters\"). Names are encoded as SCHEME_KEY, e.g. HDFS_BYTES_READ or FILE_BYTES_READ, and parseCounterName splits on the first '_'. When a counter name passed to findCounter/addCounter contains no underscore, no scheme/key split is possible and IllegalArgumentException(\"bad fs counter name\") is thrown.","triggerScenarios":"Calling findCounter(name) or addCounter(name, displayName, value) on the file system counter group with a name lacking '_', such as \"BYTES_READ\" instead of \"HDFS_BYTES_READ\"; merging user-invented names into the fs group; addCounter(String, String, long) wiring user counters through this group.","commonSituations":"User code writing its own counters directly into the \"File System Counters\" group; libraries that emit scheme-less filesystem counter names; counters aggregation from non-Hadoop sources that drops the scheme prefix.","solutions":["Use canonical SCHEME_KEY names: uppercase filesystem scheme + '_' + key, e.g. \"HDFS_BYTES_READ\".","Put user metrics in their own group via counters.findCounter(\"mygroup\", \"BYTES_READ\") instead of the fs group.","Let the framework populate filesystem counters itself; do not hand-write into that group.","Sanitize third-party counter names at merge time: names without '_' go to a generic group."],"exampleFix":"// before\nCounter c = counters.getGroup(\"File System Counters\").findCounter(\"BYTES_READ\");\n// IllegalArgumentException: bad fs counter name\n\n// after\nCounter c = counters.getGroup(\"File System Counters\").findCounter(\"HDFS_BYTES_READ\");\n// or keep user metrics in their own group:\nCounter mine = counters.findCounter(\"myapp\", \"BYTES_READ\");","handlingStrategy":"validation","validationCode":"static boolean isValidFsCounterName(String name) {\n  int i = name.indexOf('_');\n  return i > 0 && i < name.length() - 1; // SCHEME_KEY with non-empty scheme and key\n}\n\nif (isValidFsCounterName(name)) { fsGroup.findCounter(name); }\nelse { counters.findCounter(\"mygroup\", name); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write user metrics to your own counter group, never to \"File System Counters\".","Normalize external counter names to SCHEME_KEY before merging into the fs group.","Unit-test counter-name generators to keep a fixed scheme vocabulary."],"tags":["hadoop","mapreduce","counters","filesystem-counter","naming","illegalargument"],"backgroundTag":"malformed-counter-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}