apache/flink · error · IllegalArgumentException

argument is an empty- or whitespace-only string

Error message

argument is an empty- or whitespace-only string

What it means

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.

Source

Thrown at flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java:272

        }

        return parse(text);
    }

    /**
     * Parses the given string as bytes. The supported expressions are listed under {@link
     * MemorySize}.
     *
     * @param text The string to parse
     * @return The parsed size, in bytes.
     * @throws IllegalArgumentException Thrown, if the expression cannot be parsed.
     */
    public static long parseBytes(String text) throws IllegalArgumentException {
        Objects.requireNonNull(text, "text cannot be null");

        final String trimmed = text.trim();
        if (trimmed.isEmpty()) {
            throw new IllegalArgumentException("argument is an empty- or whitespace-only string");
        }

        final int len = trimmed.length();
        int pos = 0;

        char current;
        while (pos < len && (current = trimmed.charAt(pos)) >= '0' && current <= '9') {
            pos++;
        }

        final String number = trimmed.substring(0, pos);
        final String unit = trimmed.substring(pos).trim().toLowerCase(Locale.US);

        if (number.isEmpty()) {
            throw new NumberFormatException("text does not start with a number");
        }

        final long value;

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Give the property an explicit value (e.g. 64mb) or remove the key entirely so Flink's default applies
  2. Check `text != null && !text.trim().isEmpty()` before parsing user-supplied sizes
  3. Default empty inputs to a known value in your config layer instead of passing them through

Example fix

// before
long bytes = MemorySize.parseBytes(config.get("memory.size")); // key present but empty

// after
String raw = config.get("memory.size");
long bytes = (raw == null || raw.trim().isEmpty())
        ? DEFAULT_SIZE.getBytes()
        : MemorySize.parseBytes(raw);
Defensive patterns

Strategy: validation

Validate before calling

String raw = config.get(key);
if (raw == null || raw.trim().isEmpty()) {
    raw = defaultSize; // e.g. "64mb"
}
long bytes = MemorySize.parseBytes(raw);

Try / catch

catch (IllegalArgumentException e) { /* blank config value — report the offending key, not just the message */ }

Prevention

When it happens

Trigger: MemorySize.parseBytes(""); parseBytes(" "); a config property like -Dtaskmanager.memory.network.size= (empty value) flowing into memory-size parsing.

Common situations: 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.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/aa690764eecb3b5f. Report an issue: GitHub.