apache/beam · error · IllegalArgumentException
Unable to parse '" + s + "' as a byte value.
Error message
Unable to parse '" + s + "' as a byte value.
What it means
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.").
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/resourcehints/ResourceHints.java:180
@Override
public int hashCode() {
return Long.hashCode(value);
}
public BytesHint(long value) {
this.value = value;
}
public static long parse(String s) {
Matcher m = Pattern.compile("([\\d.]+)[\\s]?([\\D]+$)").matcher(s);
if (m.find()) {
String number = m.group(1);
String suffix = m.group(2);
if (number != null && suffix != null && suffixes.containsKey(suffix)) {
return (long) (Double.parseDouble(number) * suffixes.get(suffix));
}
}
throw new IllegalArgumentException("Unable to parse '" + s + "' as a byte value.");
}
@Override
public ResourceHint mergeWithOuter(ResourceHint outer, boolean isSum) {
return isSum
? new BytesHint(value + ((BytesHint) outer).value)
: new BytesHint(Math.max(value, ((BytesHint) outer).value));
}
@Override
public byte[] toBytes() {
return String.valueOf(value).getBytes(StandardCharsets.US_ASCII);
}
}
/*package*/ static class StringHint extends ResourceHint {
private final String value;
View on GitHub (pinned to 12126d8942)
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
Example fix
// before --resourceHints=min_ram_mb=10 GiB // after --resourceHints=min_ram_mb=10240mb
Defensive patterns
Strategy: validation
Validate before calling
Pattern p = Pattern.compile("^([0-9]*\\.?\\d+)(kb|mb|gb)$");
for (String hint : hints) {
String value = hint.split("=", 2)[1];
if (!p.matcher(value).matches()) {
throw new IllegalArgumentException("Value must look like '10mb': " + value);
}
} Try / catch
try {
ResourceHints.fromOptions(options);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("as a byte value")) {
// rewrite the value using a supported suffix
}
} Prevention
- Use lowercase supported suffixes (kb, mb, gb) without spaces
- Use '.' as decimal separator
- Test hint parsing in a small harness before production launches
When it happens
Trigger: 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).
Common situations: 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').
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unparsable resource hint:
- Unable to parse JSON value
- Unknown resource hint:
- Timing number 0b" + timingNumber.toString(2) + " has more th
- No proto encoding for PaneInfoCoder, always part of Windowed
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/c333f4153e92dfb4.
Report an issue: GitHub.