{"record":{"id":"dbfdb64e0f2a11e8","repo":"alibaba/arthas","slug":"s-is-not-a-valid-size-should-be-numeric-value","errorCode":null,"errorMessage":"'{s}' is not a valid size. Should be numeric value followed by a unit, i.e. 20M. Valid units k, M, G","messagePattern":"'(.+?)' is not a valid size\\. Should be numeric value followed by a unit, i\\.e\\. 20M\\. Valid units k, M, G","errorType":"validation","errorClass":"NumberFormatException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java","lineNumber":356,"sourceCode":"        process.appendResult(result);\n        process.end();\n    }\n\n    public long parseSize(String s) throws Exception {\n        s = s.toLowerCase();\n        if (s.endsWith(\"b\")) {\n            return Long.parseLong(s.substring(0, s.length() - 1).trim());\n        } else if (s.endsWith(\"k\")) {\n            return 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());\n        } else if (s.endsWith(\"m\")) {\n            return 1024 * 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());\n        } else if (s.endsWith(\"g\")) {\n            return 1024 * 1024 * 1024 * Long.parseLong(s.substring(0, s.length() - 1).trim());\n        } else {\n            try {\n                return Long.parseLong(s);\n            } catch (Exception e) {\n                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\");\n            }\n        }\n    }\n\n    public long parseTimespan(String s) throws Exception {\n        s = s.toLowerCase();\n        if (s.endsWith(\"s\")) {\n            return TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);\n        } else if (s.endsWith(\"m\")) {\n            return 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);\n        } else if (s.endsWith(\"h\")) {\n            return 60 * 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);\n        } else if (s.endsWith(\"d\")) {\n            return 24 * 60 * 60 * TimeUnit.NANOSECONDS.convert(Long.parseLong(s.substring(0, s.length() - 1).trim()), TimeUnit.SECONDS);\n        } else {\n            try {\n                return Long.parseLong(s);\n            } catch (NumberFormatException var2) {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java#L338-L374","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Use a single lowercase unit char with an integer: 20m, 1g, 500k, or a bare byte count.","Avoid decimals and multi-char units (MB/KB/GB).","Trim whitespace before passing the value."],"exampleFix":"// before\njfr --maxsize 20MB\n\n// after\njfr --maxsize 20m","handlingStrategy":"validation","validationCode":"if (!s.matches(\"\\\\d+[bkmgBKMG]?\")) {\n    // reject before calling parseSize\n}","typeGuard":"static boolean isValidSize(String s) { return s != null && s.matches(\"(?i)\\\\d+[bkmg]?\"); }","tryCatchPattern":"try { long bytes = cmd.parseSize(s); } catch (NumberFormatException e) { /* prompt user for a valid size like 20m */ }","preventionTips":["Use single-char lowercase units (k/m/g/b) with integers.","Avoid decimals and multi-char units (MB/KB/GB).","Validate the value against the unit grammar before submission."],"tags":["jfr","user-input","parsing","configuration"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}