Uploaded image for project: 'Maven Resolver'
  1. Maven Resolver
  2. MRESOLVER-314

Getting "IllegalArgumentException: Comparison method violates its general contract!"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.9.4
    • 1.9.5
    • Resolver
    • None

    Description

      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:

      Finally, the implementor must ensure that x.compareTo==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

      Here is some short demo code (truncated to the bare minimum I could find):

      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);
                      }
                  }
              }
          }
      }
      

      The output of above code is:

      0f224b94-SNAPSHOT.compareTo(ecb174eb-SNAPSHOT) := 0
      0f224b94-SNAPSHOT.compareTo(de09eebc-SNAPSHOT) := 0
      ecb174eb-SNAPSHOT.compareTo(0f224b94-SNAPSHOT) := 0
      ecb174eb-SNAPSHOT.compareTo(de09eebc-SNAPSHOT) := 1
      de09eebc-SNAPSHOT.compareTo(0f224b94-SNAPSHOT) := 0
      de09eebc-SNAPSHOT.compareTo(ecb174eb-SNAPSHOT) := -1
      

      Just for reference, here is the exception we are getting:

      Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
          at java.util.ComparableTimSort.mergeHi (ComparableTimSort.java:870)
          at java.util.ComparableTimSort.mergeAt (ComparableTimSort.java:487)
          at java.util.ComparableTimSort.mergeCollapse (ComparableTimSort.java:413)
          at java.util.ComparableTimSort.sort (ComparableTimSort.java:213)
          at java.util.Arrays.sort (Arrays.java:1315)
          at java.util.Arrays.sort (Arrays.java:1509)
          at java.util.ArrayList.sort (ArrayList.java:1750)
          at java.util.Collections.sort (Collections.java:145)
          at org.apache.maven.repository.internal.DefaultVersionRangeResolver.resolveVersionRange (DefaultVersionRangeResolver.java:168)
          at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveVersionRange (DefaultRepositorySystem.java:247)
          at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions (DefaultVersionsHelper.java:183)
          at org.codehaus.mojo.versions.api.DefaultVersionsHelper.lookupArtifactVersions (DefaultVersionsHelper.java:236)
          at org.codehaus.mojo.versions.api.PropertyVersions.resolveAssociatedVersions (PropertyVersions.java:89)
          at org.codehaus.mojo.versions.api.PropertyVersions.<init> (PropertyVersions.java:80)
          at org.codehaus.mojo.versions.api.PropertyVersionsBuilder.newPropertyVersions (PropertyVersionsBuilder.java:86)
          at org.codehaus.mojo.versions.api.DefaultVersionsHelper.getVersionPropertiesMap (DefaultVersionsHelper.java:586)
          at org.codehaus.mojo.versions.SetPropertyMojo.update (SetPropertyMojo.java:141)
          at org.codehaus.mojo.versions.SetPropertyMojo.update (SetPropertyMojo.java:135)
          at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.process (AbstractVersionsUpdaterMojo.java:329)
          at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.execute (AbstractVersionsUpdaterMojo.java:270)
      

      Attachments

        Issue Links

          Activity

            People

              cstamas Tamas Cservenak
              christianz Christian Ziech
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: