alibaba/arthas · warning · NumberFormatException

'{s}' is not a valid size. Should be numeric value followed

Error message

'{s}' is not a valid size. Should be numeric value followed by a unit, i.e. 20M. Valid units k, M, G

What it means

Thrown as NumberFormatException by JFRCommand.parseSize when the input string does not end in a recognized unit (b/k/m/g, case-insensitive) AND cannot be parsed as a bare long. The helper accepts a number optionally suffixed with b, k, m, g; anything else falls through to Long.parseLong, whose failure is rethrown with this descriptive message.

Source

Thrown at core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java:356

        process.appendResult(result);
        process.end();
    }

    public long parseSize(String s) throws Exception {
        s = s.toLowerCase();
        if (s.endsWith("b")) {
            return Long.parseLong(s.substring(0, s.length() - 1).trim());
        } else if (s.endsWith("k")) {
            return 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());
        } else if (s.endsWith("m")) {
            return 1024 * 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());
        } else if (s.endsWith("g")) {
            return 1024 * 1024 * 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());
        } else {
            try {
                return Long.parseLong(s);
            } catch (Exception e) {
                throw new NumberFormatException("'" + s + "' is not a valid size. Should be numeric value followed by a unit, i.e. 20M. Valid units k, M, G");
            }
        }
    }

    public long parseTimespan(String s) throws Exception {
        s = s.toLowerCase();
        if (s.endsWith("s")) {
            return TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);
        } else if (s.endsWith("m")) {
            return 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);
        } else if (s.endsWith("h")) {
            return 60 * 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);
        } else if (s.endsWith("d")) {
            return 24 * 60 * 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);
        } else {
            try {
                return Long.parseLong(s);
            } catch (NumberFormatException var2) {

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Use a single lowercase unit char with an integer: 20m, 1g, 500k, or a bare byte count.
  2. Avoid decimals and multi-char units (MB/KB/GB).
  3. Trim whitespace before passing the value.

Example fix

// before
jfr --maxsize 20MB

// after
jfr --maxsize 20m
Defensive patterns

Strategy: validation

Validate before calling

if (!s.matches("\\d+[bkmgBKMG]?")) {
    // reject before calling parseSize
}

Type guard

static boolean isValidSize(String s) { return s != null && s.matches("(?i)\\d+[bkmg]?"); }

Try / catch

try { long bytes = cmd.parseSize(s); } catch (NumberFormatException e) { /* prompt user for a valid size like 20m */ }

Prevention

When it happens

Trigger: Pass a --maxsize (or similar size option) value with an unknown unit (e.g. '20mb', '1.5G', '20KB'), a non-numeric token, or empty string. Decimal values and uppercase multi-letter units like 'KB'/'MB' are NOT supported (only single char k/m/g/b).

Common situations: User types '20MB' instead of '20m'; uses decimals ('1.5g'); uses '20kb'; leaves a stray character; copy-pastes a value with the wrong unit style.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/dbfdb64e0f2a11e8. Report an issue: GitHub.