Version comparator in ToolchainDiscoverer uses lexicographic String.compareTo instead of numeric version comparison
@elharo is already working on this.
Since Jul 22, 2026.
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
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
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/maven-toolchains-plugin
-
NPE during display-discovered-jdk-toolchains goal in ToolchainDiscoverer.discoverToolchains()Possibly taken @efegokdemir claimed this 12 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
New select-jdk-toolchain goal should warn about empty configPossibly taken @efegokdemir claimed this 11 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Unnecessary static synchronization in ToolchainMojo causes contention in multi-module buildsPossibly taken @elharo claimed this 74 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Dead code: unreachable null check on @Parameter(required=true) in ToolchainMojoPossibly taken @efegokdemir claimed this 11 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Infinite recursion risk in ToolchainDiscoverer.getCanonicalPath() for root pathsPossibly taken @efegokdemir claimed this 11 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
All issues in apache/maven-toolchains-plugin
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/skywalking#14120 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
HMCL-dev/HMCL#6943 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
micronaut-projects/micronaut-core#13677 ·
Maintainers usually reply within 1 day
-
new feature
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/rocketmq-dashboard#5594 ·
Maintainers usually reply within 3 days