{"record":{"id":"265fcd4964cafd25","repo":"apache/maven","slug":"unable-to-parse-version-constraint","errorCode":null,"errorMessage":"Unable to parse version constraint: ","messagePattern":"Unable to parse version constraint: ","errorType":"validation","errorClass":"VersionParserException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelVersionParser.java","lineNumber":225,"sourceCode":"            return delegate.equals(that.delegate);\n        }\n\n        @Override\n        public int hashCode() {\n            return delegate.hashCode();\n        }\n    }\n\n    static class DefaultVersionConstraint implements VersionConstraint {\n        private final VersionScheme versionScheme;\n        private final org.eclipse.aether.version.VersionConstraint delegate;\n\n        DefaultVersionConstraint(VersionScheme versionScheme, String delegateValue) {\n            this.versionScheme = versionScheme;\n            try {\n                this.delegate = versionScheme.parseVersionConstraint(delegateValue);\n            } catch (InvalidVersionSpecificationException e) {\n                throw new VersionParserException(\"Unable to parse version constraint: \" + delegateValue, e);\n            }\n        }\n\n        @Override\n        public boolean contains(Version version) {\n            if (version instanceof DefaultVersion defaultVersion) {\n                return delegate.containsVersion(defaultVersion.delegate);\n            } else {\n                return contains(new DefaultVersion(versionScheme, version.toString()));\n            }\n        }\n\n        @Override\n        public VersionRange getVersionRange() {\n            if (delegate.getRange() == null) {\n                return null;\n            }\n            return new DefaultVersionRange(versionScheme, delegate.getRange());","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelVersionParser.java#L207-L243","documentation":"DefaultModelVersionParser.DefaultVersionConstraint parses composite constraints — a version range optionally followed by a preferred version (e.g. '[1.0,2.0)1.5', '1.5') — via the resolver VersionScheme. Strings the scheme cannot interpret as a constraint throw VersionParserException('Unable to parse version constraint: <input>'). Unlike parseVersionRange, a bare version IS valid here (it becomes a recommended version), but malformed ranges, bad separators, or garbage suffixes are rejected.","triggerScenarios":"session.getService(VersionParser.class).parseVersionConstraint('[1.0') (unbalanced bracket), parseVersionConstraint('[1.0,2.0)abc') (invalid preferred version), or an uninterpolated/blank property value.","commonSituations":"Generated constraint strings concatenating range and version without correct order; blank properties defaulting to empty string; migrating code that built constraint strings by hand instead of using range+version fields; typos in the trailing recommended version.","solutions":["Build constraints in canonical form: a valid range optionally immediately followed by a valid plain version, or a single plain version","Validate the two components separately first (parseVersionRange + parseVersion) to pinpoint which half is malformed","Reject blank and '${...}' inputs before parsing"],"exampleFix":"// before\nVersionConstraint c = parser.parseVersionConstraint(range + ' ' + version); // space breaks parsing\n\n// after\nVersionConstraint c = parser.parseVersionConstraint(range + version); // e.g. '[1.0,2.0)' + '1.5'","handlingStrategy":"try-catch","validationCode":"// validate components first to pinpoint the bad half\nif (rangePart != null) parser.parseVersionRange(rangePart);\nif (versionPart != null) parser.parseVersion(versionPart);","typeGuard":null,"tryCatchPattern":"try {\n    VersionConstraint c = parser.parseVersionConstraint(spec);\n} catch (VersionParserException e) {\n    throw new IllegalArgumentException('Bad version constraint \"' + spec + '\"', e);\n}","preventionTips":["Build constraints as validRange + optional valid plain version, nothing else","Reject blank and uninterpolated inputs early","Validate the range and version halves separately for precise error messages"],"tags":["maven","version-constraint","version-range","validation"],"backgroundTag":"invalid-version-constraint","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}