You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Michael Osipov (Jira)" <ji...@apache.org> on 2022/12/24 21:44:00 UTC

[jira] [Updated] (MNG-7594) ComparableVersion#getCanonical() returns incorrect results for zero between hyphens

     [ https://issues.apache.org/jira/browse/MNG-7594?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Osipov updated MNG-7594:
--------------------------------
    Description: 
The {{getCanonical()}} method incorrectly reduces version strings like "1-0-1" to "1-1". This leads to contradictory results like in:

{{$ java -jar /path/to/maven-artifact-3.8.x.jar 1-0-1 1-1}}
{{1. 1-0-1 -> 1-1; tokens: [1, [[1]]]}}
{{   1-0-1 < 1-1}}
{{2. 1-1 -> 1-1; tokens: [1, [1]]}}

Here 1. and 2. imply that both versions should be equal, but they still compare unequal (1-0-1 < 1-1). Arguably, the correct canonicalization for 1-0-1 here should be 1-\-1 (two hyphens), since 1--1 compares equal to 1-0-1.

This is related to Bug 2 of MNG-6420, but could probably be fixed separately. I.e. just fix the broken canonicalization to make it consistent with {{compareTo()}}, but keep the comparison unchanged, without having to wait for a new spec to be written.

Note: This assumes that {{compareTo()}} is well-behaved for equality, i.e. defines a sound equivalence relation, which I think it does. It doesn't define a correct total order, as issues like MNG-6568 demonstrate, but that isn't relevant for making {{getCanonical()}} consistent with {{compareTo()}}.

  was:
The {{getCanonical()}} method incorrectly reduces version strings like "1-0-1" to "1-1". This leads to contradictory results like in:

{{$ java -jar /path/to/maven-artifact-3.8.x.jar 1-0-1 1-1}}
{{1. 1-0-1 -> 1-1; tokens: [1, [[1]]]}}
{{   1-0-1 < 1-1}}
{{2. 1-1 -> 1-1; tokens: [1, [1]]}}

Here 1. and 2. imply that both versions should be equal, but they still compare unequal (1-0-1 < 1-1). Arguably, the correct canonicalization for 1-0-1 here should be 1-\-1 (two dashes), since 1--1 compares equal to 1-0-1.

This is related to Bug 2 of MNG-6420, but could probably be fixed separately. I.e. just fix the broken canonicalization to make it consistent with {{compareTo()}}, but keep the comparison unchanged, without having to wait for a new spec to be written.

Note: This assumes that {{compareTo()}} is well-behaved for equality, i.e. defines a sound equivalence relation, which I think it does. It doesn't define a correct total order, as issues like MNG-6568 demonstrate, but that isn't relevant for making {{getCanonical()}} consistent with {{compareTo()}}.

        Summary: ComparableVersion#getCanonical() returns incorrect results for zero between hyphens  (was: ComparableVersion#getCanonical() returns incorrect results for zero between dashes)

> ComparableVersion#getCanonical() returns incorrect results for zero between hyphens
> -----------------------------------------------------------------------------------
>
>                 Key: MNG-7594
>                 URL: https://issues.apache.org/jira/browse/MNG-7594
>             Project: Maven
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 3.8.6
>            Reporter: Niklas Matthies
>            Priority: Major
>
> The {{getCanonical()}} method incorrectly reduces version strings like "1-0-1" to "1-1". This leads to contradictory results like in:
> {{$ java -jar /path/to/maven-artifact-3.8.x.jar 1-0-1 1-1}}
> {{1. 1-0-1 -> 1-1; tokens: [1, [[1]]]}}
> {{   1-0-1 < 1-1}}
> {{2. 1-1 -> 1-1; tokens: [1, [1]]}}
> Here 1. and 2. imply that both versions should be equal, but they still compare unequal (1-0-1 < 1-1). Arguably, the correct canonicalization for 1-0-1 here should be 1-\-1 (two hyphens), since 1--1 compares equal to 1-0-1.
> This is related to Bug 2 of MNG-6420, but could probably be fixed separately. I.e. just fix the broken canonicalization to make it consistent with {{compareTo()}}, but keep the comparison unchanged, without having to wait for a new spec to be written.
> Note: This assumes that {{compareTo()}} is well-behaved for equality, i.e. defines a sound equivalence relation, which I think it does. It doesn't define a correct total order, as issues like MNG-6568 demonstrate, but that isn't relevant for making {{getCanonical()}} consistent with {{compareTo()}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)