{"record":{"id":"c333f4153e92dfb4","repo":"apache/beam","slug":"unable-to-parse-s-as-a-byte-value","errorCode":null,"errorMessage":"Unable to parse '\" + s + \"' as a byte value.","messagePattern":"Unable to parse '\" \\+ s \\+ \"' as a byte value\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/resourcehints/ResourceHints.java","lineNumber":180,"sourceCode":"    @Override\n    public int hashCode() {\n      return Long.hashCode(value);\n    }\n\n    public BytesHint(long value) {\n      this.value = value;\n    }\n\n    public static long parse(String s) {\n      Matcher m = Pattern.compile(\"([\\\\d.]+)[\\\\s]?([\\\\D]+$)\").matcher(s);\n      if (m.find()) {\n        String number = m.group(1);\n        String suffix = m.group(2);\n        if (number != null && suffix != null && suffixes.containsKey(suffix)) {\n          return (long) (Double.parseDouble(number) * suffixes.get(suffix));\n        }\n      }\n      throw new IllegalArgumentException(\"Unable to parse '\" + s + \"' as a byte value.\");\n    }\n\n    @Override\n    public ResourceHint mergeWithOuter(ResourceHint outer, boolean isSum) {\n      return isSum\n          ? new BytesHint(value + ((BytesHint) outer).value)\n          : new BytesHint(Math.max(value, ((BytesHint) outer).value));\n    }\n\n    @Override\n    public byte[] toBytes() {\n      return String.valueOf(value).getBytes(StandardCharsets.US_ASCII);\n    }\n  }\n\n  /*package*/ static class StringHint extends ResourceHint {\n    private final String value;\n","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/resourcehints/ResourceHints.java#L162-L198","documentation":"BytesHint.parse converts strings like '10kb', '2.5mb' into byte counts using a regex with known suffixes. If the string doesn't match the pattern or the suffix isn't recognized, Beam throws IllegalArgumentException(\"Unable to parse '<s>' as a byte value.\").","triggerScenarios":"Passing a resource hint value like 'cpu_count=2GBx' or 'min_ram_mb=10 kilobytes' where the value fails the byte-value regex (no numeric part, unknown suffix, or both groups null/mismatched).","commonSituations":"Writing suffixes Beam doesn't know ('KB' vs 'kb', 'GiB'); including spaces ('10 kb'); passing plain unitless values where a suffix is required; locale-specific decimal commas ('1,5mb').","solutions":["Use supported suffixes exactly: e.g. '10kb', '2.5mb', '1gb' (check BytesHint suffix map)","Use a dot as the decimal separator ('1.5mb', not '1,5mb')","Remove spaces or extra characters from the value","If a unitless value is intended, confirm whether the parser accepts it or add the suffix explicitly"],"exampleFix":"// before\n--resourceHints=min_ram_mb=10 GiB\n\n// after\n--resourceHints=min_ram_mb=10240mb","handlingStrategy":"validation","validationCode":"Pattern p = Pattern.compile(\"^([0-9]*\\\\.?\\\\d+)(kb|mb|gb)$\");\nfor (String hint : hints) {\n  String value = hint.split(\"=\", 2)[1];\n  if (!p.matcher(value).matches()) {\n    throw new IllegalArgumentException(\"Value must look like '10mb': \" + value);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  ResourceHints.fromOptions(options);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"as a byte value\")) {\n    // rewrite the value using a supported suffix\n  }\n}","preventionTips":["Use lowercase supported suffixes (kb, mb, gb) without spaces","Use '.' as decimal separator","Test hint parsing in a small harness before production launches"],"tags":["java","apache-beam","resource-hints","parsing","byte-value"],"backgroundTag":"invalid-argument-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}