{"record":{"id":"eceb53f2b1e8d0f7","repo":"apache/cassandra","slug":"invalid-version-value-version","errorCode":null,"errorMessage":"Invalid version value: ${version}","messagePattern":"Invalid version value: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/CassandraVersion.java","lineNumber":105,"sourceCode":"        this.minor = minor;\n        this.patch = patch;\n        this.hotfix = hotfix;\n        this.preRelease = preRelease;\n        this.build = build;\n    }\n\n    /**\n     * Parse a version from a string.\n     *\n     * @param version the string to parse\n     * @throws IllegalArgumentException if the provided string does not\n     *                                  represent a version\n     */\n    public CassandraVersion(String version)\n    {\n        Matcher matcher = PATTERN.matcher(version);\n        if (!matcher.matches())\n            throw new IllegalArgumentException(\"Invalid version value: \" + version);\n\n        try\n        {\n            this.major = intPart(matcher, \"major\");\n            this.minor = intPart(matcher, \"minor\");\n            this.patch = intPart(matcher, \"patch\", 0);\n            this.hotfix = intPart(matcher, \"hotfix\", NO_HOTFIX);\n\n            String pr = matcher.group(\"prerelease\");\n            String bld = matcher.group(\"build\");\n\n            this.preRelease = pr == null || pr.isEmpty() ? null : parseIdentifiers(version, pr);\n            this.build = bld == null || bld.isEmpty() ? null : parseIdentifiers(version, bld);\n        }\n        catch (NumberFormatException e)\n        {\n            throw new IllegalArgumentException(\"Invalid version value: \" + version, e);\n        }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/CassandraVersion.java#L87-L123","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nCassandraVersion v = new CassandraVersion(\"v3.11.4.2\"); // IllegalArgumentException\n// after\nString cleaned = version.replaceFirst(\"^v\", \"\");\nString[] parts = cleaned.split(\"\\\\.\");\nCassandraVersion v = new CassandraVersion(String.join(\".\", Arrays.copyOfRange(parts, 0, Math.min(3, parts.length))));","handlingStrategy":"validation","validationCode":"// validate before constructing\njava.util.regex.Pattern P = java.util.regex.Pattern.compile(\"\\\\d+(\\\\.\\\\d+(\\\\.\\\\d+)?)?([-+][a-zA-Z0-9._-]+)*\");\nif (!P.matcher(version).matches()) throw new IllegalArgumentException(\"not a Cassandra version: \" + version);","typeGuard":"static boolean isParsableVersion(String s) {\n    try { new org.apache.cassandra.utils.CassandraVersion(s); return true; }\n    catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":"try {\n    CassandraVersion v = new CassandraVersion(input);\n} catch (IllegalArgumentException e) {\n    // fall back to lenient normalization or reject input\n}","preventionTips":["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"],"tags":["versioning","parsing","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}