Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Version comparator in ToolchainDiscoverer uses lexicographic String.compareTo instead of numeric version comparison

Open Beginner friendly
#166 1 comment 0 reactions 0 assignees View on GitHub

@elharo is already working on this.

Since Jul 22, 2026.

  • #177 by @elharo — merged
  • #179 by @elharo — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java
Domain
build-system

Research direction

Start at ToolchainDiscoverer.java:290-306 and inspect the version() comparator and its reversed ordering. Replace the lexicographic segment comparison with numeric version ordering, then verify that JDK versions such as 8, 10, 11, and 17 sort with the highest version first.

Written by the indexing model from the issue text.

Description

bug priority:major

Summary

The version() comparator in ToolchainDiscoverer.java uses String.compareTo() for version comparison, which is lexicographic rather than numeric. This produces incorrect sort orders for JDK versions with different digit counts.

Location

ToolchainDiscoverer.java:290-306

https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java#L290-L306

Code

Comparator<ToolchainModel> version() {
    return comparing((ToolchainModel tc) -> tc.getProvides().getProperty(VERSION), (v1, v2) -> {
                String[] a = v1.split("\\.");
                String[] b = v2.split("\\.");
                int length = Math.min(a.length, b.length);
                for (int i = 0; i < length; i++) {
                    String oa = a[i];
                    String ob = b[i];
                    if (!Objects.equals(oa, ob)) {
                        if (oa == null || ob == null) {
                            return oa == null ? -1 : 1;
                        }
                        int v = oa.compareTo(ob);
                        if (v != 0) {
                            return v;
                        }
                    }
                }
                return a.length - b.length;
            })
            .reversed();
}

Problem

String.compareTo() compares strings lexicographically, not numerically. This causes incorrect ordering:

  • "8" > "11" (because '8' > '1' in ASCII) -- WRONG, 8 < 11
  • "8" > "17" -- WRONG
  • "9" > "10" -- WRONG
  • "10" > "8" -- WRONG

The .reversed() at the end means higher versions should sort first, but this bug corrupts the ordering for any comparison between single-digit and multi-digit major versions.

Impact

JDK toolchain discovery and selection produces wrong sort order, which means select-jdk-toolchain may choose a suboptimal JDK. For example, if JDK 8 and JDK 11 are both available and match requirements, JDK 8 could be incorrectly preferred over JDK 11.

Suggested Fix

Use proper numeric version comparison (e.g., split segments and compare each segment as integers, or use a dedicated version comparator like ComparableVersion from Maven artifact API).

Dominant language
Java
Stars
27
Forks
32
Avg merge
1d 20h
Merged PRs (30d)
1

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-toolchains-plugin

All issues in apache/maven-toolchains-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.