apache/maven · warning · InvalidVersionSpecificationException

Single version must be surrounded by []

Error message

Single version must be surrounded by []: {}

What it means

The per-problem detail line under the toolchains header: each Problem is printed as 'message @ location', where location is the toolchains source file when identifiable, otherwise the default toolchains file path. Fixing every line removes the whole warning block.

Solutions

  1. Open the file named before the @ and apply the message at the reported position
  2. If the location is not a path you recognize, run mvn -X: earlier debug lines show which toolchains sources were read
  3. Correct or delete the broken <toolchain> entry and rebuild
Defensive patterns

Strategy: validation

Validate before calling

for f in ~/.m2/toolchains.xml .mvn/toolchains.xml; do
  [ -f $f ] && xmllint --noout $f
 done

Prevention

When it happens

Trigger: Any toolchains-building problem: XML that does not parse at that location, a toolchain entry missing required fields, or invalid values detected while merging user and project sources.

Common situations: Multiple toolchains sources (user plus project) making it unclear which file the location refers to; provisioning scripts emitting syntactically valid but semantically incomplete entries.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/2c863c2d4491b67f. Report an issue: GitHub.

Appendix: source

Thrown at compat/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java:173

        cached = new VersionRange(version, restrictions);
        CACHE_SPEC.put(spec, cached);
        return cached;
    }

    private static Restriction parseRestriction(String spec) throws InvalidVersionSpecificationException {
        boolean lowerBoundInclusive = spec.startsWith("[");
        boolean upperBoundInclusive = spec.endsWith("]");

        String process = spec.substring(1, spec.length() - 1).trim();

        Restriction restriction;

        int index = process.indexOf(',');

        if (index < 0) {
            if (!lowerBoundInclusive || !upperBoundInclusive) {
                throw new InvalidVersionSpecificationException("Single version must be surrounded by []: " + spec);
            }

            ArtifactVersion version = new DefaultArtifactVersion(process);

            restriction = new Restriction(version, lowerBoundInclusive, version, upperBoundInclusive);
        } else {
            String lowerBound = process.substring(0, index).trim();
            String upperBound = process.substring(index + 1).trim();

            ArtifactVersion lowerVersion = null;
            if (!lowerBound.isEmpty()) {
                lowerVersion = new DefaultArtifactVersion(lowerBound);
            }
            ArtifactVersion upperVersion = null;
            if (!upperBound.isEmpty()) {
                upperVersion = new DefaultArtifactVersion(upperBound);
            }

View on GitHub (pinned to e4093d4e12)