google/tsunami-security-scanner · error · IllegalArgumentException
Invalid range of versions, got
Error message
Invalid range of versions, got '%s'
What it means
VersionRange.parse requires exactly one comma separating the minimum and maximum bounds of the range. If the inner string contains zero commas or more than one, the range cannot be split into a min/max pair and this IllegalArgumentException is thrown.
Solutions
- Ensure the range contains exactly one comma: "[min,max]" format.
- Parse each range separately and combine with VersionSet instead of comma-joining multiple ranges.
- If you only have a single version, use Version.fromString rather than a range.
Example fix
// before
VersionRange.parse("[1.0,2.0,3.0]");
// after
VersionRange.parse("[1.0,2.0]"); Defensive patterns
Strategy: validation
Validate before calling
if (rangeString != null && rangeString.replaceAll("^[\\[\\(]|[\\]\\)]$", "").trim().chars().filter(c -> c == ',').count() == 1) { VersionRange.parse(rangeString); } Type guard
boolean hasSingleComma(String s) { return s != null && s.indexOf(',') == s.lastIndexOf(',') && s.indexOf(',') >= 0; } Try / catch
try { VersionRange.parse(rangeString); } catch (IllegalArgumentException e) { log.error("Invalid range '{}'", rangeString); } Prevention
- Always use [min,max] form with exactly one comma.
- Do not comma-join multiple ranges; use VersionSet.
- Reject single-version strings before treating them as ranges.
When it happens
Trigger: Calling VersionRange.parse with strings like "[1.0]" (no comma), "[1.0,2.0,3.0]" (two commas), or "[1.0 2.0]" after the bracket validation has passed.
Common situations: Typing a discrete version where a range is expected ("[1.0.0]" without comma), joining multiple ranges with commas instead of parsing them separately, or locale mistakes inserting extra separators.
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.
Related errors
- Parenthesis and/or brackets not allowed within version…
- Infinity range is not supported, got
- String ' ' is neither a discrete string nor a version range.
AI-assisted analysis of google/tsunami-security-scanner@363ba87b35 (2026-09-13).
Data as JSON: /api/errors/ead02b37bb9ef185.
Report an issue: GitHub.
Appendix: source
Thrown at common/src/main/java/com/google/tsunami/common/version/VersionRange.java:152
if (!rangeString.endsWith("]") && !rangeString.endsWith(")")) {
throw new IllegalArgumentException(
String.format("Version range must end with ']' or ')', got '%s'", rangeString));
}
// Remove the leading and ending parenthesis and brackets.
String trimmedRange = rangeString.substring(1, rangeString.length() - 1).trim();
// No more parenthesis and brackets in the string.
if (CharMatcher.anyOf("[()]").matchesAnyOf(trimmedRange)) {
throw new IllegalArgumentException(
String.format(
"Parenthesis and/or brackets not allowed within version range, got '%s'",
rangeString));
}
// Only one comma that separates the minimum and maximum.
if (CharMatcher.is(',').countIn(trimmedRange) != 1) {
throw new IllegalArgumentException(
String.format("Invalid range of versions, got '%s'", rangeString));
}
// Version range of minimum to maximum is not supported.
if (trimmedRange.equals(",")) {
throw new IllegalArgumentException(
String.format("Infinity range is not supported, got '%s'", rangeString));
}
}
}
View on GitHub (pinned to 363ba87b35)