{"record":{"id":"39328323f2fd1bd8","repo":"bazelbuild/bazel","slug":"invalid-size-input","errorCode":null,"errorMessage":"Invalid size: \" + input","messagePattern":"Invalid size: \" \\+ input","errorType":"validation","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/Converters.java","lineNumber":697,"sourceCode":"    private static final Pattern PATTERN =\n        Pattern.compile(\"(?<value>[0-9]+)(?<multiplier>[KMGT]?)\");\n\n    private static final ImmutableMap<String, Long> MULTIPLIER_MAP =\n        ImmutableMap.of(\n            \"K\",\n            1024L,\n            \"M\",\n            1024L * 1024L,\n            \"G\",\n            1024L * 1024L * 1024L,\n            \"T\",\n            1024L * 1024L * 1024L * 1024L);\n\n    @Override\n    public Long convert(String input) throws OptionsParsingException {\n      Matcher m = PATTERN.matcher(input);\n      if (!m.matches()) {\n        throw new OptionsParsingException(\"Invalid size: \" + input);\n      }\n      try {\n        long value = Long.parseLong(m.group(\"value\"));\n        String mult = m.group(\"multiplier\");\n        if (!mult.isEmpty()) {\n          value = Math.multiplyExact(value, (long) MULTIPLIER_MAP.get(mult));\n        }\n        return value;\n      } catch (NumberFormatException | ArithmeticException e) {\n        throw new OptionsParsingException(\"Invalid size: \" + input, e);\n      }\n    }\n\n    @Override\n    public String getTypeDescription() {\n      return \"a size in bytes, optionally followed by a K, M, G or T multiplier\";\n    }\n  }","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/Converters.java#L679-L715","documentation":"Thrown by ByteSizeConverter.convert when the input does not match its PATTERN at all — i.e. it is not a number optionally followed by a K/M/G/T multiplier suffix (e.g. 'abc', '1X', '1.5G' if fractions are not in the pattern). This is the pre-parse rejection, before Long.parseLong or the multiplier math is attempted.","triggerScenarios":"Passing a non-numeric or wrongly-suffixed value to any byte-size flag (e.g. --memory_limit, JVM heap-style flags using this converter): 'unlimited', '1B' (B suffix unsupported per the type description), '10 K' with a space, '1.5G'.","commonSituations":"Assuming 'B' or lowercase 'k'/'m' suffixes work, leaving shell-expanded spaces inside the value, passing a unit like '500MB' instead of '500M', flags scripted from variables that come out empty or as 'null'.","solutions":["Use the documented form: integer optionally followed by one of K, M, G, T (e.g. 1024, 512M, 4G).","Remove spaces and unsupported suffixes: '500MB' -> '500M', '10 K' -> '10K'.","If the value comes from a script, validate with regex ^[0-9]+[KMGT]?$ before invoking bazel."],"exampleFix":"# before\n--experimental_disk_cache_size=500MB\n\n# after\n--experimental_disk_cache_size=500M","handlingStrategy":"validation","validationCode":"// Mirror the parser's accepted grammar before invoking bazel\nboolean isValidSize(String s) {\n  return s != null && s.matches(\"[0-9]+[KMGT]?\");\n}","typeGuard":null,"tryCatchPattern":"Catch OptionsParsingException around flag parsing; e.getMessage() includes the invalid input verbatim, so fail fast with that context rather than retrying.","preventionTips":["Use only integer + optional single K/M/G/T suffix","Trim whitespace from script-generated values before passing","Reject 'B'/'MB'/'KB' suffixes at the script layer"],"tags":["options-parsing","byte-size","converter","bazel"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}