apache/flink · error · IllegalArgumentException

Memory size unit '{unit}' does not match any of the recogniz

Error message

Memory size unit '{unit}' does not match any of the recognized units: {MemoryUnit.getAllUnits()}

What it means

MemorySize.parseBytes (via parseUnit) throws IllegalArgumentException listing all recognized units when the trailing unit string matches none of them. Units are case-insensitive but must exactly match a supported spelling (b/bytes, k/kb/kilo..., m/mb/mega..., g/gb/giga..., t/tb/tera...). Note decimal separators are not stripped: '1.5gb' parses number '1' and unit '.5gb', landing here.

Source

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

                            + "' cannot be re represented as 64bit number of bytes (numeric overflow).");
        }

        return result;
    }

    private static Optional<MemoryUnit> parseUnit(String unit) {
        if (matchesAny(unit, BYTES)) {
            return Optional.of(BYTES);
        } else if (matchesAny(unit, KILO_BYTES)) {
            return Optional.of(KILO_BYTES);
        } else if (matchesAny(unit, MEGA_BYTES)) {
            return Optional.of(MEGA_BYTES);
        } else if (matchesAny(unit, GIGA_BYTES)) {
            return Optional.of(GIGA_BYTES);
        } else if (matchesAny(unit, TERA_BYTES)) {
            return Optional.of(TERA_BYTES);
        } else if (!unit.isEmpty()) {
            throw new IllegalArgumentException(
                    "Memory size unit '"
                            + unit
                            + "' does not match any of the recognized units: "
                            + MemoryUnit.getAllUnits());
        }

        return Optional.empty();
    }

    private static boolean matchesAny(String str, MemoryUnit unit) {
        for (String s : unit.getUnits()) {
            if (s.equals(str)) {
                return true;
            }
        }
        return false;
    }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Use a recognized unit: b/bytes, kb, mb, gb, tb (case-insensitive) with a whole number
  2. Convert decimals to a smaller unit: 1.5gb -> 1536mb
  3. Remove stray characters/punctuation around the unit in the config value

Example fix

# before
taskmanager.memory.framework.heap.size: 1.5gb

# after
taskmanager.memory.framework.heap.size: 1536mb
Defensive patterns

Strategy: validation

Validate before calling

private static final Pattern SIZE = Pattern.compile("\\d+(b|bytes|k|kb|kb(s)?|m|mb|g|gb|t|tb)", Pattern.CASE_INSENSITIVE);
if (!SIZE.matcher(raw.trim()).matches()) {
    throw new IllegalArgumentException("Unrecognized memory size format: '" + raw + "'");
}
long bytes = MemorySize.parseBytes(raw);

Try / catch

catch (IllegalArgumentException e) { /* message lists all valid units — surface it to the user for config fixes */ }

Prevention

When it happens

Trigger: parseBytes("1.5gb") (dot becomes part of the unit); parseBytes("100pb") or "100xb"; unit typos like 'gm' or 'mbyte'; values like "1 gb " are fine after trim/lowercase but "1g-b" is not.

Common situations: Decimal memory values in config (unsupported — must use whole numbers with a smaller unit); using SI-only or vendor-specific unit spellings Flink does not recognize; stray punctuation attached to the unit.

Related errors


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