Uploaded image for project: '[Read Only] - Hippo Repository'
  1. [Read Only] - Hippo Repository
  2. REPO-260

Failing contract when implementing Comparable throws IllegalArgumentException in JAVA 7

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • High
    • Resolution: Fixed
    • None
    • 2.24.02
    • None
    • None

    Description

      with java7, we see stacktraces like below. I think, although not tested, that this is a result from some Comparable implementations that do not comply to the Comparable compareTo contract of transitivity:

      <p>The implementor must ensure <tt>sgn(x.compareTo) == -sgn(y.compareTo)</tt> for all <tt>x</tt> and <tt>y</tt>.

      Before java 7, this seemed to be not a problem when violating this contract. For example, the class below breaks this contract:

      public int compareTo(FacetSearchEntry entry) {
      if(entry == null)

      { throw new NullPointerException(); }

      if(entry.equals(this))

      { return 0; }

      if(entry.count.count - this.count.count == 0)

      { return 1; }

      return (entry.count.count - this.count.count);
      }

      We'll do a test now what happens if we 'fix' this one. If that works, we should

      1) Check all our code for compareTo's that break the contract
      2) Come up with a version that is transitive (not always easy, what to do with the above if count's are equal? Return the diff between the hashCode's? They can also be the same)
      3) Hope that we do not rely on projects that have the same problem

      OTOH, perhaps they 'fix' it in java 7 to be more relaxed regarding breaking the contract

      Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
      at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:714)
      at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:451)
      at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:376)
      at java.util.ComparableTimSort.sort(ComparableTimSort.java:182)
      at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
      at java.util.Arrays.sort(Arrays.java:472)
      at org.hippoecm.repository.jackrabbit.AbstractFacetSearchProvider.populate(AbstractFacetSearchProvider.java:206)
      at org.hippoecm.repository.jackrabbit.HippoLocalItemStateManager.getItemState(HippoLocalItemStateManager.java:383)
      at org.apache.jackrabbit.core.state.SessionItemStateManager.getItemState(SessionItemStateManager.java:161)
      at org.hippoecm.repository.security.HippoAccessManager.getItemState(HippoAccessManager.java:1026)
      at org.hippoecm.repository.security.HippoAccessManager.canRead(HippoAccessManager.java:474)
      at org.hippoecm.repository.security.HippoAccessManager.canRead(HippoAccessManager.java:1156)
      at org.apache.jackrabbit.core.query.lucene.QueryResultImpl.isAccessGranted(QueryResultImpl.java:355)
      at org.apache.jackrabbit.core.query.lucene.QueryResultImpl.collectScoreNodes(QueryResultImpl.java:334)
      at org.apache.jackrabbit.core.query.lucene.QueryResultImpl.getResults(QueryResultImpl.java:291)
      at org.hippoecm.repository.query.lucene.HippoQueryResult.<init>(HippoQueryResult.java:64)
      at org.hippoecm.repository.query.lucene.ServicingSearchIndex$2.execute(ServicingSearchIndex.java:152)

      Attachments

        Activity

          People

            svoortman Simon Voortman (Inactive)
            aschrijvers Ard Schrijvers
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: