You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNG-7594] ComparableVersion#getCanonical() returns incorrect results for zero between hyphens #8873
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().
The more I read such issues there more I think that we need to apply strict semantics versioning becasue there will be always cases with a lenient format which will fail. :-(
[MNG-7594] Fix ComparableVersion getCanonical for zero between hyphens
Summary
Resolves the issue where version strings like 1-0-1 had contradictory canonicalization and comparison results. Previously, ListItem.normalize() removed intermediate zero elements before child lists, resulting in 1-0-1 being canonicalized to 1-1 while still sorting as 1-0-1 < 1-1.
Changes
ListItem.normalize():
Added safe pattern matching and non-empty guards when inspecting following ListItem entries before determining if preceding null/zero items can be pruned.
This is already fixed on master and on maven-4.0.x: 1-0-1 now canonicalizes to 1-0-1, compares equal to 1--1 and below 1-1. The fix came with #13102 (MNG-6568), and #13441 added the regression test (ComparableVersionTest#testMng7594).
It is not fixed on maven-3.10.x, where 1-0-1 still canonicalizes to 1-1. The 3.x ComparableVersion is a different implementation, so #13102 cannot be backported as is. It also changes the ordering that 3.x has always had: on 3.10.x 1.0-1 equals 1-1, on master it is greater. Fixing only the canonical form on 3.10.x would hit the same rule, so I did not open a PR for it. Maintainers, is a change in 3.10.x wanted here? Otherwise this issue can be closed as fixed in 4.x.
Activity
jira-importer commentedon Nov 8, 2022
Michael Osipov commented
The more I read such issues there more I think that we need to apply strict semantics versioning becasue there will be always cases with a lenient format which will fail. :-(
Tarun4201 commentedon Oct 12, 2026
[MNG-7594] Fix ComparableVersion getCanonical for zero between hyphens
Summary
Resolves the issue where version strings like
1-0-1had contradictory canonicalization and comparison results. Previously,ListItem.normalize()removed intermediate zero elements before child lists, resulting in1-0-1being canonicalized to1-1while still sorting as1-0-1 < 1-1.Changes
ListItem.normalize():ListItementries before determining if preceding null/zero items can be pruned.ComparableVersionTest#testMng7594):1-0-1canonicalizes to1-0-1and compares equal to1--1.1-0-1 < 1-1andcanonical("1-0-1") != canonical("1-1").1-0-2 < 1-0.1 < 1-2from MNG-6420, multiple hyphenated zeros1-0-0-1, and normalized trailing zeros like1-0-1-0 == 1-0-1).arturobernalg commentedon Oct 16, 2026
This is already fixed on master and on maven-4.0.x:
1-0-1now canonicalizes to1-0-1, compares equal to1--1and below1-1. The fix came with #13102 (MNG-6568), and #13441 added the regression test (ComparableVersionTest#testMng7594).It is not fixed on maven-3.10.x, where
1-0-1still canonicalizes to1-1. The 3.xComparableVersionis a different implementation, so #13102 cannot be backported as is. It also changes the ordering that 3.x has always had: on 3.10.x1.0-1equals1-1, on master it is greater. Fixing only the canonical form on 3.10.x would hit the same rule, so I did not open a PR for it. Maintainers, is a change in 3.10.x wanted here? Otherwise this issue can be closed as fixed in 4.x.Keep the zero between hyphens in the canonical form of a version (fix #…