oracle/graal · error · IllegalArgumentException
Unrecognized unit prefix: {size} use `T`, `G`, `M`, or `k`.
Error message
Unrecognized unit prefix: {size} use `T`, `G`, `M`, or `k`. What it means
The final switch of the size converter accepts only T/t, G/g, M/m, K/k as the single unit character. Any other character after the digits (e.g. 'B', 'b', 'i') falls to default and throws, advising the four supported prefixes.
Source
Thrown at espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java:584
long result = Long.parseLong(size.substring(0, idx));
if (idx < len) {
switch (size.charAt(idx)) {
case 'T': // fallthrough
case 't':
return result * K * K * K * K;
case 'G': // fallthrough
case 'g':
return result * K * K * K;
case 'M': // fallthrough
case 'm':
return result * K * K;
case 'K': // fallthrough
case 'k':
return result * K;
default:
throw new IllegalArgumentException("Unrecognized unit prefix: " + size + " use `T`, `G`, `M`, or `k`.");
}
}
return result;
}
});
@Option(help = "Maximum total size of NIO direct-buffer allocations.", //
category = OptionCategory.EXPERT, //
stability = OptionStability.STABLE, usageSyntax = "<size>[<unit>]") //
public static final OptionKey<Long> MaxDirectMemorySize = new OptionKey<>(-1L, SIZE_OPTION_TYPE);
@Option(help = "Load native agents from standard library paths. \\n" +
"Keys represent the agent library name, values are the corresponding agent options.\\n" +
"Agents are not fully implemented yet.", //
category = OptionCategory.INTERNAL, //
stability = OptionStability.EXPERIMENTAL, //
usageSyntax = "<agentOptions>") //View on GitHub (pinned to a66e9ccd1d)
Solutions
- Use T, G, M, or k (case-insensitive) as the unit.
- For plain bytes, omit the unit entirely.
- Beware that 'b' is NOT accepted - use no unit for bytes.
Example fix
# before --java.MaxDirectMemorySize=16B # after --java.MaxDirectMemorySize=16 # bytes, no unit
Defensive patterns
Strategy: validation
Validate before calling
if (!size.matches("\\d+([TtGgMmKk])?")) throw new ConfigException("Unit must be T/G/M/k: " + size); Type guard
static boolean validUnit(String s) { return s != null && s.matches("\\d+[TtGgMmKk]?"); } Prevention
- Plain bytes = no suffix at all.
- Remember 'B'/'b' are rejected.
When it happens
Trigger: --java.MaxDirectMemorySize=16B, 1b, or 1x - the value starts with digits and has exactly one trailing character, but that character is not T/G/M/K.
Common situations: Writing '16B' for bytes (use a plain number instead); binary-unit 'i' from GiB notation; typos.
Related errors
- Not starting with digits: {size}
- Unit prefix can be at most one character: {size}
- --java.SpecCompliance: Mode can be 'strict' or 'hotspot'.
- -Xverify: Mode can be 'none', 'remote' or 'all'.
- --java.LivenessAnalysis can only be 'none'|'false', 'auto' o
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/04de453703b49d79.
Report an issue: GitHub.