{"record":{"id":"15a2fbefb196b9f4","repo":"apache/cassandra","slug":"value-s-is-not-a-valid-human-readable-file-size","errorCode":null,"errorMessage":"value %s is not a valid human-readable file size","messagePattern":"value (.+?) is not a valid human-readable file size","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/io/util/FileUtils.java","lineNumber":332,"sourceCode":"    }\n\n    public static String getCanonicalPath(File file)\n    {\n        return file.canonicalPath();\n    }\n\n    /** Return true if file is contained in folder */\n    public static boolean isContained(File folder, File file)\n    {\n        return folder.isAncestorOf(file);\n    }\n\n    public static long parseFileSize(String value)\n    {\n        long result;\n        if (!value.matches(\"\\\\d+(\\\\.\\\\d+)? (GiB|KiB|MiB|TiB|bytes)\"))\n        {\n            throw new IllegalArgumentException(\n                String.format(\"value %s is not a valid human-readable file size\", value));\n        }\n        if (value.endsWith(\" TiB\"))\n        {\n            result = Math.round(Double.valueOf(value.replace(\" TiB\", \"\")) * ONE_TIB);\n            return result;\n        }\n        else if (value.endsWith(\" GiB\"))\n        {\n            result = Math.round(Double.valueOf(value.replace(\" GiB\", \"\")) * ONE_GIB);\n            return result;\n        }\n        else if (value.endsWith(\" KiB\"))\n        {\n            result = Math.round(Double.valueOf(value.replace(\" KiB\", \"\")) * ONE_KIB);\n            return result;\n        }\n        else if (value.endsWith(\" MiB\"))","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/FileUtils.java#L314-L350","documentation":"parseFileSize(String) throws IllegalArgumentException when the input does not match the pattern '\\d+(\\.\\d+)? (GiB|KiB|MiB|TiB|bytes)' — a number, one space, and one of the exact binary units. The format is strict: no 'KB'/'GB' decimal units, no missing space, no bare numbers.","triggerScenarios":"Calling FileUtils.parseFileSize with values like '10MB', '10 MB', '1024', '1.5 GiB ' (trailing space), or lowercase 'mib'.","commonSituations":"Users writing cassandra.yaml-style sizes with decimal units (MB/GB) into APIs expecting binary human-readable units; programmatic config generation emitting unspaced or unprefixed values; whitespace/case mistakes.","solutions":["Format the value as '<number> <UNIT>' with a single space and unit in {bytes, KiB, MiB, GiB, TiB}.","Convert decimal units (MB→MiB etc.) or rewrite as raw byte counts elsewhere.","Pre-parse/validate with the same regex before calling."],"exampleFix":"// before\nFileUtils.parseFileSize(\"10MB\"); // throws\n\n// after\nFileUtils.parseFileSize(\"10 MiB\"); // OK","handlingStrategy":"validation","validationCode":"private static final Pattern SIZE = Pattern.compile(\"\\\\d+(\\\\.\\\\d+)? (GiB|KiB|MiB|TiB|bytes)\");\nboolean isValidSize(String v) { return v != null && SIZE.matcher(v).matches(); }","typeGuard":"boolean isHumanReadableSize(String v) { return v != null && v.matches(\"\\\\d+(\\\\.\\\\d+)? (GiB|KiB|MiB|TiB|bytes)\"); }","tryCatchPattern":"try { long n = FileUtils.parseFileSize(v); } catch (IllegalArgumentException e) { /* normalize unit and retry */ }","preventionTips":["Always emit sizes as '<number> <binary unit>' with exactly one space.","Convert MB/GB (decimal) to MiB/GiB before parsing.","Centralize size-string formatting in one utility."],"tags":["parsing","format","config"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}