title: Collections.sort throws IllegalArgumentException
body: <p>i am trying to sort a list of object that holds string and a double value:</p>
  
  <pre><code>lock.tryLock();
      if (testTagRev.size() &gt; 0)
  Collections.sort(testTagRev, documentSampleComperator);
  lock.unlock();
  </code></pre>
  
  <p>documentSampleComperator is a type documentSampleComparer:</p>
  
  <pre><code>class documentSampleComparer implements Comparator&lt;DocumentSample&gt; {
      @Override
      public int compare(DocumentSample x, DocumentSample y) {
          int ans = x.getText().toString().compareTo(y.getText().toString());
          // ans = utils.listToString(x.getText(), ' ').compareTo(utils.listToString(y.getText(),' ')); also didn't work
          if (ans == 0)
              return Integer.compare(x.hashCode(), y.hashCode());
          else return ans;
      }
  }
  </code></pre>
  
  <p>even though the compactor is transitive i still get this exception :</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Comparison method     violates its general contract!
      at java.util.TimSort.mergeLo(TimSort.java:747)
      at java.util.TimSort.mergeAt(TimSort.java:483)
  at java.util.TimSort.mergeCollapse(TimSort.java:410)
  at java.util.TimSort.sort(TimSort.java:214)
  at java.util.TimSort.sort(TimSort.java:173)
  at java.util.Arrays.sort(Arrays.java:659)
  at java.util.Collections.sort(Collections.java:217)
  at Trainer.MCobjectStream.&lt;init&gt;(MCobjectStream.java:64)
  at Trainer.filterRev.&lt;init&gt;(filterRev.java:64)
  at Trainer.Train.main(Train.java:56)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  </code></pre>
  
  <p>I am using jdk 1.7.0_45 , can you see where is the problem ?</p>
  
  <p><strong>Edit</strong>: utils.listToString turn's list of string to a string, added the lock code and comment the line that i was trying to make it work before .
  also i should mention that the exception only occurred sometimes but <strong>i am not using</strong> threads .</p>