Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7594

ComparableVersion#getCanonical() returns incorrect results for zero between hyphens

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.8.6
    • None
    • Core
    • None

    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().

      Attachments

        Activity

          People

            Unassigned Unassigned
            matthies Niklas Matthies
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: