[ 
https://issues.apache.org/jira/browse/MNG-6420?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17008025#comment-17008025
 ] 

Elliotte Rusty Harold commented on MNG-6420:
--------------------------------------------

For #2 the text is "The version order is the lexicographical order on this 
sequence of prefixed tokens, the shorter one padded with enough "null" values 
with matching prefix to have the same length as the longer one. Padded "null" 
values depend on the prefix of the other version: 0 for '.', "" for '-'. "


Thus to compare "2" and "2.q" we do

1. Convert "2" into the sequence ["2"]. Call this sequence A.
2. Convert "2.q" into the sequence ["2", ".q"]. Call this sequence B.
3. Pad the first sequence A with the null value ".0" so it becomes ["2", ".0"]
4. Now compare ["2", ".0"] to ["2", ".q"]
5. Key step: ".0" > ".q" because all numbers are greater than all non-numbers
6. Therefore  ["2", ".0"] > ["2", ".q"]
7. Therefore "2" > "2.q"

However step 5 isn't actually covered by the spec.


For #3 my intuition without working this out in detail is that 2.q should be 
greater than 2 or 2.0. I don't know if that's a common belief or not. I may do 
a twitter poll on this one.






> ComparableVersion incorrectly parses certain version strings
> ------------------------------------------------------------
>
>                 Key: MNG-6420
>                 URL: https://issues.apache.org/jira/browse/MNG-6420
>             Project: Maven
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.5.3, 3.6.3
>            Reporter: Ross Goldberg
>            Priority: Major
>
> For certain version strings, ComparableVersion doesn't follow the Maven 
> version order spec 
> (https://maven.apache.org/pom.html#Version_Order_Specification), and/or 
> produces canonical versions that are incongruent with both the spec and the 
> code's ordering.
> To improve the code & fix the following bugs, I completely rewrote the 
> version parser (using Java 8).  I will create a PR sometime soon.
> *Bug 1: comparison violates spec ordering*
>  
> java -jar /usr/local/Cellar/maven/3.5.3/libexec/lib/maven-artifact-3.6.3.jar 
> 1-0.3 1
>  
> Outputs:
>  
> 1. 1-0.3 == 1-0.3
>    1-0.3 == 1
> 2. 1 == 1
>  
> This problem stems from:
>  
> [https://github.com/apache/maven/blob/b8c06e61ab73cd9e25a5b2c93d9e5077b2196751/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java#L295-L296]
>  
>  
>  
> *Bug 2: canonical incongruent with spec and code ordering*
>  
> java -jar /usr/local/Cellar/maven/3.5.3/libexec/lib/maven-artifact-3.6.3.jar 
> 1-0-2 1-0.1
>  
> 1. 1-0-2 == 1-2
>    1-0-2 < 1-0.1
> 2. 1-0.1 == 1-0.1
>  
> This problem stems from retaining ListItems that, after normalization, have 
> no children other than the subsequent ListItem.  Removing the unnecessary 
> ListItem should fix this (i.e. remove the extraneous ListItem (named 
> extraneous) from its parent ListItem (named parent), then add the only child 
> of extraneous to parent).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to