apache/hadoop · error · IllegalArgumentException
Invalid size prefix '{}' in '{}'. Allowed prefixes are k, m,
Error message
Invalid size prefix '{}' in '{}'. Allowed prefixes are k, m, g, t, p, e(case insensitive) What it means
StringUtils.string2long trims the input, and if the last character is a digit it parses the whole string as a long; otherwise it looks the last character up as a traditional binary prefix. When that lookup fails (any character other than k, m, g, t, p, e, case-insensitive), the IllegalArgumentException from valueOf is caught and rethrown with this message telling you the allowed prefixes. This is the friendly wrapper around the 'Unknown symbol' error (error 1840).
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java:917
* For example,
* "-1230k" will be converted to -1230 * 1024 = -1259520;
* "891g" will be converted to 891 * 1024^3 = 956703965184;
*
* @param s input string
* @return a long value represented by the input string.
*/
public static long string2long(String s) {
s = s.trim();
final int lastpos = s.length() - 1;
final char lastchar = s.charAt(lastpos);
if (Character.isDigit(lastchar))
return Long.parseLong(s);
else {
long prefix;
try {
prefix = TraditionalBinaryPrefix.valueOf(lastchar).value;
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid size prefix '" + lastchar
+ "' in '" + s
+ "'. Allowed prefixes are k, m, g, t, p, e(case insensitive)");
}
long num = Long.parseLong(s.substring(0, lastpos));
if (num > (Long.MAX_VALUE/prefix) || num < (Long.MIN_VALUE/prefix)) {
throw new IllegalArgumentException(s + " does not fit in a Long");
}
return num * prefix;
}
}
/**
* Convert a long integer to a string with traditional binary prefix.
*
* @param n the value to be converted
* @param unit The unit, e.g. "B" for bytes.
* @param decimalPlaces The number of decimal places.
* @return a string with traditional binary prefix.View on GitHub (pinned to 2add963021)
Solutions
- Rewrite the value with a valid bare prefix: '512m', '2g', '1t' (k=1024, m=1024^2, g=1024^3, t=1024^4, p=1024^5, e=1024^6).
- Remove trailing 'b'/'B' from generated config values before they reach string2long.
- Pre-validate input with a regex such as ^-?\d+[kKmMgGtTpPeE]?$ before calling string2long so you control the error message.
- Wrap the call in try/catch IllegalArgumentException to produce a config-validation error naming the offending property.
Example fix
// before
long v = StringUtils.string2long(conf.get("mapred.task.mem", "512mb"));
// throws: Invalid size prefix 'B' in '512mb'
// after
long v = StringUtils.string2long(conf.get("mapred.task.mem", "512m")); Defensive patterns
Strategy: validation
Validate before calling
private static final Pattern SIZE = Pattern.compile("^-?\d+([kKmMgGtTpPeE])?$");
static boolean isParsableSize(String s) {
return s != null && SIZE.matcher(s.trim()).matches();
}
// use before StringUtils.string2long
if (!isParsableSize(val)) {
throw new IllegalArgumentException("Property value '" + val
+ "' must be a number optionally suffixed with k/m/g/t/p/e");
} Try / catch
try {
long bytes = StringUtils.string2long(value);
} catch (IllegalArgumentException e) {
LOG.error("Bad size value '" + value + "' for property " + propName, e);
throw new ConfigurationException(propName, e.getMessage());
} Prevention
- Document accepted suffixes (k, m, g, t, p, e — no 'b') wherever size configs are exposed.
- Reject values with unit words ('mb', 'gb') at config load with a clear message.
- Add unit tests covering suffix variants to catch regressions in config generators.
When it happens
Trigger: string2long("1KB") — 'B' is not a prefix; string2long("abc") — 'c' is not a valid prefix letter; string2long("10GiB") — 'i'... actually last char 'B' invalid; string2long("5x"); any input whose final character is a non-digit outside the allowed set. Note: if the prefix letter is valid but the leading part is not numeric (e.g. '12abg'), you get NumberFormatException from Long.parseLong instead, not this error.
Common situations: Memory/size configuration values written with a byte unit ('512mb', '2gb') instead of Hadoop's bare prefix ('512m', '2g'); copying SI units ('1KiB') or network-style units ('10Mb') into configs parsed by string2long; trailing unit characters like '%' or 'B' from templated config files.
Related errors
- Unknown symbol '{}'
- {} does not fit in a Long
- Errors on getting mount table loader class. The fs.viewfs.mo
- %s=null: %s: %s
- Codec not configured for custom codec {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/5d7e1bde7987ee53.
Report an issue: GitHub.