Christian Ziech created MRESOLVER-314:
-----------------------------------------
Summary: Getting "IllegalArgumentException: Comparison method
violates its general contract!"
Key: MRESOLVER-314
URL: https://issues.apache.org/jira/browse/MRESOLVER-314
Project: Maven Resolver
Issue Type: Bug
Components: Resolver
Affects Versions: 1.9.4
Reporter: Christian Ziech
We are using the versions plugin to modify the version of a property in our pom
files. This now fails for us because the compareTo method of the compareTo()
method of the org.eclipse.aether.util.version.GenericVersion violates the
assumption that the relation is transitive.
I wrote a small test which shows that
0f224b94-SNAPSHOT.compareTo(ecb174eb-SNAPSHOT) := 0 and
0f224b94-SNAPSHOT.compareTo(de09eebc-SNAPSHOT) := 0 but
ecb174eb-SNAPSHOT.compareTo(de09eebc-SNAPSHOT) := 1.
This is in violation with:
{quote}
Finally, the implementor must ensure that x.compareTo(y)==0 implies that
sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
{quote}
Here is some short demo code (truncated to the bare minimum I could find):
{code}
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
public class TestMavenResolver {
public void testCompare() throws InvalidVersionSpecificationException {
String [] strs = new String [] {"0f224b94-SNAPSHOT",
"ecb174eb-SNAPSHOT", "de09eebc-SNAPSHOT"};
List<Version> versions = new ArrayList<>();
GenericVersionScheme scheme = new GenericVersionScheme();
for (String str: strs) {
versions.add(scheme.parseVersion(str));
}
for (Version ver1 : versions) {
for (Version ver2 : versions) {
if (ver1 != ver2) {
int res = ver1.compareTo(ver2);
System.out.println(ver1+".compareTo("+ver2+") := "+res);
}
}
}
}
}
{code}
Just for reference, here is the exception we are getting:
{noformat}
java.lang.IllegalArgumentException: Comparison method violates its general
contract!
at
java.base/java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:870)
at
java.base/java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:487)
at
java.base/java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:413)
at
java.base/java.util.ComparableTimSort.sort(ComparableTimSort.java:213)
at java.base/java.util.Arrays.sort(Arrays.java:1315)
at java.base/java.util.Arrays.sort(Arrays.java:1509)
at java.base/java.util.ArrayList.sort(ArrayList.java:1750)
at java.base/java.util.Collections.sort(Collections.java:145)
{noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)