{"record":{"id":"ebb904bbae6e3446","repo":"apache/druid","slug":"unkonwn-unit-system-s","errorCode":null,"errorMessage":"Unkonwn unit system[%s]","messagePattern":"Unkonwn unit system\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java","lineNumber":262,"sourceCode":"   * @param precision  [0,3]\n   * @param unitSystem which unit system is adopted to format the input value, see {@link UnitSystem}\n   */\n  public static String format(long bytes, long precision, UnitSystem unitSystem)\n  {\n    if (precision < 0 || precision > 3) {\n      throw new IAE(\"precision [%d] must be in the range of [0,3]\", precision);\n    }\n\n    String pattern = \"%.\" + precision + \"f %s%s\";\n    switch (unitSystem) {\n      case BINARY_BYTE:\n        return BinaryFormatter.format(bytes, pattern, \"B\");\n      case DECIMAL_BYTE:\n        return DecimalFormatter.format(bytes, pattern, \"B\");\n      case DECIMAL:\n        return DecimalFormatter.format(bytes, pattern, \"\").trim();\n      default:\n        throw new IAE(\"Unkonwn unit system[%s]\", unitSystem);\n    }\n  }\n\n  static class BinaryFormatter\n  {\n    private static final String[] UNITS = {\"\", \"Ki\", \"Mi\", \"Gi\", \"Ti\", \"Pi\", \"Ei\"};\n\n    static String format(long bytes, String pattern, String suffix)\n    {\n      if (bytes > -1024 && bytes < 1024) {\n        return bytes + \" \" + suffix;\n      }\n\n      if (bytes == Long.MIN_VALUE) {\n        /**\n         * special path for Long.MIN_VALUE\n         *\n         * Long.MIN_VALUE = 2^63 = (2^60=1EiB) * 2^3","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java#L244-L280","documentation":"HumanReadableBytes.format switches over the provided UnitSystem enum; the default branch throws this (typo 'Unkonwn') if the unit system is not one of BINARY_BYTE, DECIMAL_BYTE, DECIMAL. Since UnitSystem is an enum, reaching default is nearly impossible in normal Java but can occur with foreign enum constants in switching/reflection-based scenarios or when the enum gains new constants in one version while this method's switch lags.","triggerScenarios":"Passing null as the UnitSystem (switch on null throws NPE, but older/greedy dispatch paths can hit default), or a custom/newly added UnitSystem constant not covered by the switch after a library upgrade.","commonSituations":"Reflective or serialized enum values from another Druid version; code written against a fork of the enum; dynamic dispatch frameworks mapping integers to enum constants.","solutions":["Pass only HumanReadableBytes.UnitSystem.BINARY_BYTE, DECIMAL_BYTE, or DECIMAL","Null-check the UnitSystem argument before calling format","After upgrading Druid, recompile so enum switches are exhaustive against the new version"],"exampleFix":"// before\nHumanReadableBytes.format(1024, 2, null); // IAE/NPE at default\n// after\nHumanReadableBytes.format(1024, 2, UnitSystem.BINARY_BYTE);","handlingStrategy":"type-guard","validationCode":"if (unitSystem == null) {\n  throw new IllegalArgumentException(\"unitSystem must not be null\");\n}","typeGuard":"if (unitSystem == HumanReadableBytes.UnitSystem.BINARY_BYTE\n    || unitSystem == HumanReadableBytes.UnitSystem.DECIMAL_BYTE\n    || unitSystem == HumanReadableBytes.UnitSystem.DECIMAL) {\n  // safe to format\n}","tryCatchPattern":"try {\n  return HumanReadableBytes.format(bytes, precision, unitSystem);\n} catch (IllegalArgumentException e) {\n  return HumanReadableBytes.format(bytes, precision, HumanReadableBytes.UnitSystem.DECIMAL_BYTE);\n}","preventionTips":["Only pass the three declared UnitSystem constants","Null-check enum parameters coming from deserialization or maps","Recompile after Druid upgrades that touch the UnitSystem enum"],"tags":["bytes","enum","formatting"],"backgroundTag":"invalid-enum-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}