[MNG-7594] ComparableVersion#getCanonical() returns incorrect results for zero between hyphens
- Dominant language
- Java
- Stars
- 5.3k
- Forks
- 3.1k
- Avg merge
- 20h 42m
- Merged PRs (30d)
- 297
Description
**[Niklas Matthies](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=matthies)** opened **[MNG-7594](https://issues.apache.org/jira/browse/MNG-7594?redirect=false)** and commented
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()`.
---
**Affects:** 3.8.6
Contributor guide
Assessment
This issue has not been assessed yet.