diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java index 811bab2f5e..23eb846b86 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java @@ -530,8 +530,16 @@ public class ComparableVersion { return 0; // 1-0 = 1- (normalize) = 1 } - Item first = get( 0 ); - return first.compareTo( null ); + // Compare the entire list of items with null - not just the first one, MNG-6964 + for ( Item i : this ) + { + int result = i.compareTo( null ); + if ( result != 0 ) + { + return result; + } + } + return 0; } switch ( item.getType() ) { diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java index 70fc1d8ecc..97fb46d55f 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -295,6 +295,21 @@ public class ComparableVersionTest checkVersionsArrayEqual( arr ); } + /** + * Test MNG-6964 edge cases + * for qualifiers that start with "-0.", which was showing A == C and B == C but A < B. + */ + public void testMng6964() + { + String a = "1-0.alpha"; + String b = "1-0.beta"; + String c = "1"; + + checkVersionsOrder( a, c ); // Now a < c, but before MNG-6964 they were equal + checkVersionsOrder( b, c ); // Now b < c, but before MNG-6964 they were equal + checkVersionsOrder( a, b ); // Should still be true + } + public void testLocaleIndependent() { Locale orig = Locale.getDefault();