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

  1. Use a single-character unit: 16G, 512k, 128M, 1T.
  2. Or give the exact byte count with no unit.
  3. 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

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


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/4ec982001be261df. Report an issue: GitHub.