apache/druid · error · IllegalArgumentException
Invalid format of number: %s
Error message
Invalid format of number: %s
What it means
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').
Source
Thrown at processing/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java:156
return nullValue;
}
return parseInner(number);
}
private static long parseInner(String rawNumber)
{
String number = StringUtils.toLowerCase(rawNumber);
if (number.charAt(0) == '-') {
throw new IAE("Invalid format of number: %s. Negative value is not allowed.", rawNumber);
}
int lastDigitIndex = number.length() - 1;
boolean isBinaryByte = false;
char unit = number.charAt(lastDigitIndex--);
if (unit == 'b') {
//unit ends with 'b' must be format of KiB/MiB/GiB/TiB/PiB, so at least 3 extra characters are required
if (lastDigitIndex < 2) {
throw new IAE("Invalid format of number: %s", rawNumber);
}
if (number.charAt(lastDigitIndex--) != 'i') {
throw new IAE("Invalid format of number: %s", rawNumber);
}
unit = number.charAt(lastDigitIndex--);
isBinaryByte = true;
} else if (unit == 'i') {
//unit ends with 'i' must be format of Ki/Mi/Gi/Ti/Pi, so at least 2 extra characters are required
if (lastDigitIndex < 1) {
throw new IAE("Invalid format of number [%s]. The unit should be one of Pi/Ti/Gi/Mi/Ki", rawNumber);
}
unit = number.charAt(lastDigitIndex--);
isBinaryByte = true;
}
long base = 1;
switch (unit) {View on GitHub (pinned to 9b90983fd2)
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
Example fix
// before
long bytes = HumanReadableBytes.parse("1024b"); // invalid
// after
long bytes = HumanReadableBytes.parse("1024"); // plain bytes Defensive patterns
Strategy: validation
Validate before calling
private static final Pattern HUMAN_BYTES = Pattern.compile("^\\d+\\s*(k|m|g|t|p)?(i?[b]?)?$", Pattern.CASE_INSENSITIVE);
if (raw == null || !HUMAN_BYTES.matcher(raw.trim()).matches()) {
throw new IllegalArgumentException("Invalid byte size format: " + raw);
} Try / catch
try {
long bytes = HumanReadableBytes.parse(raw);
} catch (IAE e) {
throw new IllegalArgumentException("Bad size string '" + raw + "'; use forms like 1024, 100mb, 128MiB", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Metric [%s] not whitelisted.
- Invalid format of number: number is null
- Invalid format of number: number is blank
- Invalid format of number: %s. Negative value is not allowed.
- Invalid format of number [%s]. The unit should be one of Pi/
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/ca6b0a0b1084876a.
Report an issue: GitHub.