apache/pulsar · error · IllegalArgumentException

Invalid size '%s'. Valid formats are: (4096, 100K, 10M, 16G,

Error message

Invalid size '%s'. Valid formats are: (4096, 100K, 10M, 16G, 2T)

What it means

Size-string parse failure in ByteUnitUtil.validateSizeString: the trailing character is a unit (k/K/m/M/g/G/t/T) but the numeric prefix is not a valid integer, or NumberFormatException otherwise — i.e. the string is malformed relative to the accepted '<number>[unit]' grammar; the byteStr argument is the faulty input.

Source

Thrown at pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/ByteUnitUtil.java:46

public class ByteUnitUtil {

    private static Set<Character> sizeUnit = Collections.unmodifiableSet(
            new HashSet<>(Arrays.asList('k', 'K', 'm', 'M', 'g', 'G', 't', 'T')));

    public static long validateSizeString(String byteStr) {
        if (byteStr.isEmpty()) {
            throw new IllegalArgumentException("byte string cannot be empty");
        }

        char last = byteStr.charAt(byteStr.length() - 1);
        String subStr = byteStr.substring(0, byteStr.length() - 1);
        long size;
        try {
            size = sizeUnit.contains(last)
                    ? Long.parseLong(subStr)
                    : Long.parseLong(byteStr);
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(String.format("Invalid size '%s'. Valid formats are: %s",
                    byteStr, "(4096, 100K, 10M, 16G, 2T)"));
        }
        switch (last) {
            case 'k':
            case 'K':
                return size * 1024;

            case 'm':
            case 'M':
                return size * 1024 * 1024;

            case 'g':
            case 'G':
                return size * 1024 * 1024 * 1024;

            case 't':
            case 'T':
                return size * 1024 * 1024 * 1024 * 1024;

View on GitHub (pinned to 820761864e)

Solutions

  1. Use one of the accepted formats: 4096, 100K, 10M, 16G, 2T
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/ByteUnitUtil.java:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/45a0d5d5c622c57f. Report an issue: GitHub.