elharo opened a new issue, #166:
URL: https://github.com/apache/maven-toolchains-plugin/issues/166

   ## Summary
   
   The  comparator in  uses  for version comparison, which is lexicographic 
rather than numeric. This produces incorrect sort orders for JDK versions with 
different digit counts.
   
   ## Location
   
   
   
   
https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java#L290-L306
   
   ## Code
   
   
   
   ## Problem
   
    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  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 
 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  from Maven 
artifact API).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to