{"record":{"id":"ca6b0a0b1084876a","repo":"apache/druid","slug":"invalid-format-of-number-s","errorCode":null,"errorMessage":"Invalid format of number: %s","messagePattern":"Invalid format of number: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java","lineNumber":156,"sourceCode":"      return nullValue;\n    }\n    return parseInner(number);\n  }\n\n  private static long parseInner(String rawNumber)\n  {\n    String number = StringUtils.toLowerCase(rawNumber);\n    if (number.charAt(0) == '-') {\n      throw new IAE(\"Invalid format of number: %s. Negative value is not allowed.\", rawNumber);\n    }\n\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) {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java#L138-L174","documentation":"HumanReadableBytes.parseInner throws this IllegalArgumentException when the string ends in 'b' but is too short or malformed to be a binary unit like KiB/MiB/GiB/TiB/PiB — the parser requires at least three characters before the final 'b' (a digit and a binary prefix such as 'Ki').","triggerScenarios":"Calling parse with inputs like \"b\", \"5b\", \"kib\" (no digits), or \"12b\" — anything ending in 'b' lacking the required Ki/Mi/Gi/Ti/Pi prefix pattern.","commonSituations":"Users writing \"1024b\" expecting a plain-bytes suffix (the library treats trailing 'b' as binary-unit syntax); typo'd units like \"mb\" written as lowercase plus 'b' confusion; abbreviated docs examples.","solutions":["Use a plain number for bytes (e.g. \"1024\" instead of \"1024b\")","Use the correct binary form \"KiB\"/\"MiB\" etc. if a binary unit was intended (e.g. \"128MiB\")","Use decimal units like \"mb\"/\"gb\" for powers of 1000 instead of trailing 'b'","Catch IAE and display the accepted formats (digits, K/M/G/T/P, KiB/MiB/...) in validation UI"],"exampleFix":"// before\nlong bytes = HumanReadableBytes.parse(\"1024b\"); // invalid\n// after\nlong bytes = HumanReadableBytes.parse(\"1024\"); // plain bytes","handlingStrategy":"validation","validationCode":"private static final Pattern HUMAN_BYTES = Pattern.compile(\"^\\\\d+\\\\s*(k|m|g|t|p)?(i?[b]?)?$\", Pattern.CASE_INSENSITIVE);\nif (raw == null || !HUMAN_BYTES.matcher(raw.trim()).matches()) {\n  throw new IllegalArgumentException(\"Invalid byte size format: \" + raw);\n}","typeGuard":null,"tryCatchPattern":"try {\n  long bytes = HumanReadableBytes.parse(raw);\n} catch (IAE e) {\n  throw new IllegalArgumentException(\"Bad size string '\" + raw + \"'; use forms like 1024, 100mb, 128MiB\", e);\n}","preventionTips":["Remember trailing 'b' must follow a full binary unit (KiB/MiB/GiB/TiB/PiB); use a bare number for plain bytes","Prefer unambiguous forms: digits only, or KiB/MiB style, or kb/mb/gb decimal","Add format validation in UIs and config loaders before calling parse","Share accepted-format docs with operators editing runtime.properties"],"tags":["configuration","parsing","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"}