{"record":{"id":"4ec982001be261df","repo":"oracle/graal","slug":"unit-prefix-can-be-at-most-one-character-size","errorCode":null,"errorMessage":"Unit prefix can be at most one character: {size}","messagePattern":"Unit prefix can be at most one character: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java","lineNumber":564,"sourceCode":"        private static final int K = 1024;\n\n        @Override\n        public Long apply(String size) {\n            int idx = 0;\n            int len = size.length();\n            for (int i = 0; i < len; i++) {\n                if (Character.isDigit(size.charAt(i))) {\n                    idx++;\n                } else {\n                    break;\n                }\n            }\n\n            if (idx == 0) {\n                throw new IllegalArgumentException(\"Not starting with digits: \" + size);\n            }\n            if (len - idx > 1) {\n                throw new IllegalArgumentException(\"Unit prefix can be at most one character: \" + size);\n            }\n\n            long result = Long.parseLong(size.substring(0, idx));\n\n            if (idx < len) {\n                switch (size.charAt(idx)) {\n                    case 'T': // fallthrough\n                    case 't':\n                        return result * K * K * K * K;\n                    case 'G': // fallthrough\n                    case 'g':\n                        return result * K * K * K;\n                    case 'M': // fallthrough\n                    case 'm':\n                        return result * K * K;\n                    case 'K': // fallthrough\n                    case 'k':\n                        return result * K;","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java#L546-L582","documentation":"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.","triggerScenarios":"--java.MaxDirectMemorySize=16GB or 512kb - multi-letter units like GB/MB/KB/kib are not accepted.","commonSituations":"Muscle memory from -Xmx16GB style or Kubernetes resource strings; unit strings produced by formatting libraries.","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."],"exampleFix":"# before\n--java.MaxDirectMemorySize=16GB\n\n# after\n--java.MaxDirectMemorySize=16G","handlingStrategy":"validation","validationCode":"if (!size.matches(\"\\\\d+[TtGgMmKk]?\")) throw new ConfigException(\"Unit must be at most one char: \" + size);","typeGuard":"static boolean singleCharUnit(String s) { return s != null && s.matches(\"\\\\d{1,19}[TtGgMmKk]?\"); }","tryCatchPattern":null,"preventionTips":["Never use GB/MB/KB/GiB - only single-letter units.","Normalize memory strings from k8s or -Xmx formats before passing them on."],"tags":["espresso","graalvm","configuration","options","memory"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}