{"record":{"id":"9f36fa926f98f647","repo":"apache/flink","slug":"text-does-not-start-with-a-number","errorCode":null,"errorMessage":"text does not start with a number","messagePattern":"text does not start with a number","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java","lineNumber":287,"sourceCode":"\n        final String trimmed = text.trim();\n        if (trimmed.isEmpty()) {\n            throw new IllegalArgumentException(\"argument is an empty- or whitespace-only string\");\n        }\n\n        final int len = trimmed.length();\n        int pos = 0;\n\n        char current;\n        while (pos < len && (current = trimmed.charAt(pos)) >= '0' && current <= '9') {\n            pos++;\n        }\n\n        final String number = trimmed.substring(0, pos);\n        final String unit = trimmed.substring(pos).trim().toLowerCase(Locale.US);\n\n        if (number.isEmpty()) {\n            throw new NumberFormatException(\"text does not start with a number\");\n        }\n\n        final long value;\n        try {\n            value = Long.parseLong(number); // this throws a NumberFormatException on overflow\n        } catch (NumberFormatException e) {\n            throw new IllegalArgumentException(\n                    \"The value '\"\n                            + number\n                            + \"' cannot be re represented as 64bit number (numeric overflow).\");\n        }\n\n        final long multiplier = parseUnit(unit).map(MemoryUnit::getMultiplier).orElse(1L);\n        final long result = value * multiplier;\n\n        // check for overflow\n        if (result / multiplier != value) {\n            throw new IllegalArgumentException(","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java#L269-L305","documentation":"MemorySize.parseBytes throws NumberFormatException(\"text does not start with a number\") when the trimmed input has no leading ASCII digits. The parser first scans only characters 0-9, so input like \"gb\", \"1gb\" is fine but \"gb1\", \"-1mb\", or \".5gb\" yields an empty numeric part and this exception. Note this is a NumberFormatException even though sibling failures use IllegalArgumentException.","triggerScenarios":"parseBytes(\"gb\"); parseBytes(\"-1mb\") (the '-' stops digit scanning); parseBytes(\".5gb\") (leading dot is not a digit); values whose unit was concatenated before the number.","commonSituations":"Negative memory values in config (rejected here because the parser only accepts unsigned integers); decimal values like 1.5gb (only the integer part is scanned — use whole numbers with a smaller unit instead); typos in unit strings.","solutions":["Write sizes as an unsigned integer followed by a unit: 512mb, 1g, 1024","For fractional sizes, convert to a smaller unit (1.5gb -> 1536mb)","Strip nothing — leading '+'/'-' signs and decimals are not supported; fix the producer of the string"],"exampleFix":"# before\ntaskmanager.memory.task.heap.size: -1m\n\n# after\ntaskmanager.memory.task.heap.size: 64m","handlingStrategy":"validation","validationCode":"if (!raw.trim().matches(\"\\\\d+.*\")) {\n    throw new IllegalArgumentException(\"Memory size '\" + raw + \"' must start with an unsigned integer (e.g. 64m)\");\n}\nlong bytes = MemorySize.parseBytes(raw);","typeGuard":null,"tryCatchPattern":"catch (NumberFormatException e) { /* note: subclass of IllegalArgumentException; input lacks leading digits — fix the string format */ }","preventionTips":["Always write sizes as unsigned integer + unit (512mb, 1g)","No negative signs, decimals, or leading units are accepted","Convert 1.5gb to 1536mb"],"tags":["memory","parsing","number-format","configuration","flink-core-api"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}