{"record":{"id":"aa690764eecb3b5f","repo":"apache/flink","slug":"argument-is-an-empty-or-whitespace-only-string","errorCode":null,"errorMessage":"argument is an empty- or whitespace-only string","messagePattern":"argument is an empty- or whitespace-only string","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java","lineNumber":272,"sourceCode":"        }\n\n        return parse(text);\n    }\n\n    /**\n     * Parses the given string as bytes. The supported expressions are listed under {@link\n     * MemorySize}.\n     *\n     * @param text The string to parse\n     * @return The parsed size, in bytes.\n     * @throws IllegalArgumentException Thrown, if the expression cannot be parsed.\n     */\n    public static long parseBytes(String text) throws IllegalArgumentException {\n        Objects.requireNonNull(text, \"text cannot be null\");\n\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;","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java#L254-L290","documentation":"MemorySize.parseBytes(String) throws IllegalArgumentException(\"argument is an empty- or whitespace-only string\") when the input, after trimming, contains no characters. Parsing must have at least a numeric part, so blank input is rejected before any number/unit analysis.","triggerScenarios":"MemorySize.parseBytes(\"\"); parseBytes(\"   \"); a config property like -Dtaskmanager.memory.network.size= (empty value) flowing into memory-size parsing.","commonSituations":"Optional memory settings left empty in flink-conf.yaml, env vars, or CLI -D flags; string concatenation building \"1gb\" producing an empty string when a variable is unset.","solutions":["Give the property an explicit value (e.g. 64mb) or remove the key entirely so Flink's default applies","Check `text != null && !text.trim().isEmpty()` before parsing user-supplied sizes","Default empty inputs to a known value in your config layer instead of passing them through"],"exampleFix":"// before\nlong bytes = MemorySize.parseBytes(config.get(\"memory.size\")); // key present but empty\n\n// after\nString raw = config.get(\"memory.size\");\nlong bytes = (raw == null || raw.trim().isEmpty())\n        ? DEFAULT_SIZE.getBytes()\n        : MemorySize.parseBytes(raw);","handlingStrategy":"validation","validationCode":"String raw = config.get(key);\nif (raw == null || raw.trim().isEmpty()) {\n    raw = defaultSize; // e.g. \"64mb\"\n}\nlong bytes = MemorySize.parseBytes(raw);","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) { /* blank config value — report the offending key, not just the message */ }","preventionTips":["Omit optional memory keys entirely rather than setting them empty","Blank-check raw config strings before parsing","Unit-test config parsing with empty/whitespace inputs"],"tags":["memory","configuration","parsing","validation","flink-core-api"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}