apache/hadoop · error · IllegalArgumentException
{} does not fit in a Long
Error message
{} does not fit in a Long What it means
After splitting a prefixed value into a number and a 1024^n multiplier, StringUtils.string2long explicitly checks num > Long.MAX_VALUE/prefix (or the MIN_VALUE bound for negatives) so that the multiplication cannot silently overflow. When the scaled result would leave the 64-bit signed long range, it throws this IllegalArgumentException. Example: '100000000e' means 10^8 * 2^60, but Long.MAX_VALUE / 2^60 is about 8, so it is rejected.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java:923
*/
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.
*/
public static String long2String(long n, String unit, int decimalPlaces) {
if (unit == null) {
unit = "";
}
//take care a special caseView on GitHub (pinned to 2add963021)
Solutions
- Lower the configured value so number * 1024^n fits in a signed 64-bit long (e.g. <= 8 with 'e', <= 8388608 with 'g', <= 8589934592 with 'm').
- Drop the suffix and use the plain digit form if you genuinely need Long.MAX_VALUE: '9223372036854775807'.
- Validate the magnitude before calling string2long (Math.abs(num) <= Long.MAX_VALUE / prefix) and emit a targeted config error.
- Catch IllegalArgumentException around config parsing to report which property overflowed instead of failing deep in startup.
Example fix
// before
long quota = StringUtils.string2long("100000000e"); // 10^8 * 2^60 > Long.MAX
// throws: 100000000e does not fit in a Long
// after
long quota = StringUtils.string2long("8e"); // 8 * 2^60, fits Defensive patterns
Strategy: validation
Validate before calling
static boolean fitsInLong(String s) {
s = s.trim();
char last = s.charAt(s.length() - 1);
if (Character.isDigit(last)) {
return true; // Long.parseLong will enforce range
}
char u = Character.toUpperCase(last);
long[] mult = {1024L, 1L<<20, 1L<<30, 1L<<40, 1L<<50, 1L<<60};
char[] syms = {'K','M','G','T','P','E'};
for (int i = 0; i < syms.length; i++) {
if (u == syms[i]) {
long num = Long.parseLong(s.substring(0, s.length() - 1));
return num <= Long.MAX_VALUE / mult[i] && num >= Long.MIN_VALUE / mult[i];
}
}
return false;
}
if (!fitsInLong(val)) {
throw new IllegalArgumentException("Value '" + val + "' overflows a long");
} Try / catch
try {
long quota = StringUtils.string2long(value);
} catch (IllegalArgumentException e) {
// e.getMessage() says '<value> does not fit in a Long' or names a bad prefix
throw new ConfigurationException("size property: " + e.getMessage(), e);
} Prevention
- Cap user-supplied size configs at sane operational bounds (e.g. <= a few petabytes) instead of long range.
- For max-size defaults use the plain digit form Long.MAX_VALUE with no suffix.
- Test oversized inputs in config validation unit tests.
When it happens
Trigger: string2long("100000000e"), string2long("99999999999g"), string2long("9007199254740993k"); any value whose numeric part exceeds Long.MAX_VALUE (or is below Long.MIN_VALUE) after division by the prefix multiplier. Negative overflows hit the num < Long.MIN_VALUE/prefix branch, e.g. '-100000000e'.
Common situations: Oversized heap/disk/cache size settings (values past 8 exabytes when suffixed with 'e'); test fixtures with extra digits; copy-pasting Long.MAX_VALUE plus a 'g'/'t' suffix; generated configs computing size expressions that explode past long range.
Related errors
- Unknown symbol '{}'
- Invalid size prefix '{}' in '{}'. Allowed prefixes are k, m,
- Address should be <host>:<port>, but it is {}
- Bad format: {}
- src.toString() + ": No such file or directory"
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/5b2e4e3c47ce242c.
Report an issue: GitHub.