{"record":{"id":"fbf8043801ec438e","repo":"apache/druid","slug":"invalid-format-of-number-s-the-unit-should-be","errorCode":null,"errorMessage":"Invalid format of number [%s]. The unit should be one of Pi/Ti/Gi/Mi/Ki","messagePattern":"Invalid format of number \\[(.+?)\\]\\. The unit should be one of Pi/Ti/Gi/Mi/Ki","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java","lineNumber":167,"sourceCode":"\n    int lastDigitIndex = number.length() - 1;\n    boolean isBinaryByte = false;\n    char unit = number.charAt(lastDigitIndex--);\n    if (unit == 'b') {\n      //unit ends with 'b' must be format of KiB/MiB/GiB/TiB/PiB, so at least 3 extra characters are required\n      if (lastDigitIndex < 2) {\n        throw new IAE(\"Invalid format of number: %s\", rawNumber);\n      }\n      if (number.charAt(lastDigitIndex--) != 'i') {\n        throw new IAE(\"Invalid format of number: %s\", rawNumber);\n      }\n\n      unit = number.charAt(lastDigitIndex--);\n      isBinaryByte = true;\n    } else if (unit == 'i') {\n      //unit ends with 'i' must be format of Ki/Mi/Gi/Ti/Pi, so at least 2 extra characters are required\n      if (lastDigitIndex < 1) {\n        throw new IAE(\"Invalid format of number [%s]. The unit should be one of Pi/Ti/Gi/Mi/Ki\", rawNumber);\n      }\n      unit = number.charAt(lastDigitIndex--);\n      isBinaryByte = true;\n    }\n\n    long base = 1;\n    switch (unit) {\n      case 'k':\n        base = isBinaryByte ? 1024 : 1_000;\n        break;\n\n      case 'm':\n        base = isBinaryByte ? 1024 * 1024 : 1_000_000;\n        break;\n\n      case 'g':\n        base = isBinaryByte ? 1024 * 1024 * 1024 : 1_000_000_000;\n        break;","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java#L149-L185","documentation":"HumanReadableBytes.parseInner throws this IllegalArgumentException when the string ends in 'i' but the remaining prefix is too short or not one of the supported binary units (Ki/Mi/Gi/Ti/Pi). Only those five binary prefixes are accepted before the 'i'.","triggerScenarios":"Calling parse with values like \"xi\", \"5kiB\" typed as \"5kib\" with an invalid prefix letter, or strings like \"100bi\" where the character before 'i' is not one of k/m/g/t/p.","commonSituations":"Misspelled units such as \"Zi\"/\"Yi\" (not supported), \"NiB\", or locale-mangled characters; users assuming all SI prefixes (e.g. 'h', 'da') work; hand-edited configs with stray characters.","solutions":["Use one of the supported units: Pi/Ti/Gi/Mi/Ki (optionally followed by b/B), e.g. \"64Ki\" or \"64KiB\"","Fall back to decimal units K/M/G/T/P (e.g. \"64k\") or a plain byte count","Correct the misspelled/unsupported prefix in the configuration string","Catch IAE and validate config at startup with a message listing acceptable units"],"exampleFix":"// before\nlong bytes = HumanReadableBytes.parse(\"64zi\"); // 'z' is not a supported unit\n// after\nlong bytes = HumanReadableBytes.parse(\"64GiB\");","handlingStrategy":"validation","validationCode":"private static final Set<Character> VALID_PREFIX = Set.of('k','m','g','t','p');\nString s = raw == null ? \"\" : raw.trim().toLowerCase();\nint i = s.indexOf('i');\nif (i > 0) {\n  char prefix = s.charAt(i - 1);\n  boolean prefixIsDigitOrValid = Character.isDigit(prefix) || VALID_PREFIX.contains(prefix);\n  if (!prefixIsDigitOrValid) throw new IllegalArgumentException(\"Unsupported unit prefix in: \" + raw);\n}","typeGuard":null,"tryCatchPattern":"try {\n  long bytes = HumanReadableBytes.parse(raw);\n} catch (IAE e) {\n  throw new IllegalArgumentException(\"Unit must be one of Pi/Ti/Gi/Mi/Ki (optionally + b/B): \" + raw, e);\n}","preventionTips":["Restrict size inputs to the five supported binary units Ki/Mi/Gi/Ti/Pi (plus decimal K/M/G/T/P)","Reject exotic prefixes (Zi/Yi/Ni) at config validation time","Document the exact supported unit list near the config key","Add unit tests covering each accepted and rejected unit spelling"],"tags":["configuration","parsing","unit-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}