apache/cassandra · error · IllegalArgumentException
Invalid version value
Error message
Invalid version value: ${version} What it means
CassandraVersion's constructor validates the input string against its semver-like PATTERN (major[.minor[.patch]][-pre][+build]). Non-matching strings are rejected with IllegalArgumentException before any parsing.
Solutions
- Normalize the version string to major.minor[-pre][+build] before constructing
- Strip a leading 'v' and extra components programmatically
- Validate with a regex or CassandraVersion.PATTERN before constructing
- Catch IllegalArgumentException and fall back to a lenient parser if flexible input must be accepted
Example fix
// before
CassandraVersion v = new CassandraVersion("v3.11.4.2"); // IllegalArgumentException
// after
String cleaned = version.replaceFirst("^v", "");
String[] parts = cleaned.split("\\.");
CassandraVersion v = new CassandraVersion(String.join(".", Arrays.copyOfRange(parts, 0, Math.min(3, parts.length)))); Defensive patterns
Strategy: validation
Validate before calling
// validate before constructing
java.util.regex.Pattern P = java.util.regex.Pattern.compile("\\d+(\\.\\d+(\\.\\d+)?)?([-+][a-zA-Z0-9._-]+)*");
if (!P.matcher(version).matches()) throw new IllegalArgumentException("not a Cassandra version: " + version); Type guard
static boolean isParsableVersion(String s) {
try { new org.apache.cassandra.utils.CassandraVersion(s); return true; }
catch (IllegalArgumentException e) { return false; }
} Try / catch
try {
CassandraVersion v = new CassandraVersion(input);
} catch (IllegalArgumentException e) {
// fall back to lenient normalization or reject input
} Prevention
- Normalize user-supplied versions (strip 'v', truncate extra segments) before parsing
- Add a regex pre-check in UIs/config loaders accepting version strings
- Never assume foreign version schemes (e.g., '1.0.0.0') parse
When it happens
Trigger: new CassandraVersion("...") with strings like "1.0.0.0.0", "v1.2.3", an empty string, or other non-semver formats, e.g., from system.local schema_version parsing, driver metadata, or user input.
Common situations: Parsing version strings with extra components or a leading 'v'; reading a version from a hand-edited config/env var; comparing against versions of other products with different schemes.
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
- A CounterId representation is exactly
- A CQL blob string must have an even length (since one byte…
- A local deletion time should not be a legacy overflowed…
- A local deletion time should not be negative
- A local deletion time should not be negative in
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/eceb53f2b1e8d0f7.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/utils/CassandraVersion.java:105
this.minor = minor;
this.patch = patch;
this.hotfix = hotfix;
this.preRelease = preRelease;
this.build = build;
}
/**
* Parse a version from a string.
*
* @param version the string to parse
* @throws IllegalArgumentException if the provided string does not
* represent a version
*/
public CassandraVersion(String version)
{
Matcher matcher = PATTERN.matcher(version);
if (!matcher.matches())
throw new IllegalArgumentException("Invalid version value: " + version);
try
{
this.major = intPart(matcher, "major");
this.minor = intPart(matcher, "minor");
this.patch = intPart(matcher, "patch", 0);
this.hotfix = intPart(matcher, "hotfix", NO_HOTFIX);
String pr = matcher.group("prerelease");
String bld = matcher.group("build");
this.preRelease = pr == null || pr.isEmpty() ? null : parseIdentifiers(version, pr);
this.build = bld == null || bld.isEmpty() ? null : parseIdentifiers(version, bld);
}
catch (NumberFormatException e)
{
throw new IllegalArgumentException("Invalid version value: " + version, e);
}View on GitHub (pinned to 88fd0f6a0e)