oracle/graal · error · IllegalArgumentException
Unit prefix can be at most one character: {size}
Error message
Unit prefix can be at most one character: {size} What it means
After the leading run of digits, the size converter allows at most one remaining character (the unit prefix). If more than one character follows the digits (e.g. '16GB', '1kb', '2Gib'), len - idx > 1 and this IllegalArgumentException is thrown.
Source
Thrown at espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java:564
private static final int K = 1024;
@Override
public Long apply(String size) {
int idx = 0;
int len = size.length();
for (int i = 0; i < len; i++) {
if (Character.isDigit(size.charAt(i))) {
idx++;
} else {
break;
}
}
if (idx == 0) {
throw new IllegalArgumentException("Not starting with digits: " + size);
}
if (len - idx > 1) {
throw new IllegalArgumentException("Unit prefix can be at most one character: " + size);
}
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;View on GitHub (pinned to a66e9ccd1d)
Solutions
- Use a single-character unit: 16G, 512k, 128M, 1T.
- Or give the exact byte count with no unit.
- Normalize human-readable sizes before passing them to the option.
Example fix
# before --java.MaxDirectMemorySize=16GB # after --java.MaxDirectMemorySize=16G
Defensive patterns
Strategy: validation
Validate before calling
if (!size.matches("\\d+[TtGgMmKk]?")) throw new ConfigException("Unit must be at most one char: " + size); Type guard
static boolean singleCharUnit(String s) { return s != null && s.matches("\\d{1,19}[TtGgMmKk]?"); } Prevention
- Never use GB/MB/KB/GiB - only single-letter units.
- Normalize memory strings from k8s or -Xmx formats before passing them on.
When it happens
Trigger: --java.MaxDirectMemorySize=16GB or 512kb - multi-letter units like GB/MB/KB/kib are not accepted.
Common situations: Muscle memory from -Xmx16GB style or Kubernetes resource strings; unit strings produced by formatting libraries.
Related errors
- Not starting with digits: {size}
- Unrecognized unit prefix: {size} use `T`, `G`, `M`, or `k`.
- --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/4ec982001be261df.
Report an issue: GitHub.