Comparison method violates its general contract(arraylist comprasion)
<p>I asked before <a href="http://stackoverflow.com/questions/16429431/compare-arraylists-of-chars-alphabetically">compare arraylists of chars alphabetically</a> how to compare arraylists of chars alphabetically. 
Now I decided to implement it. </p>

<p>Here is my comprasion method</p>

<pre><code>@Override
public int compareTo(Word o) {

    int left = this.count();
    int right = o.count();

    if (left == right){
        if (this.length() &gt; o.length()){
            try{
                for(int i = 0; i &lt; this.length(); i++){
                    if (this.get(i).compareTo(o.get(i)) &lt; 0)
                        return 1;
                }
            }catch(IndexOutOfBoundsException e){
                return -1;
            }
        }

        else {
            try{
                for(int i = 0; i &lt; o.length(); i++){
                    if (this.get(i).compareTo(o.get(i)) &lt; 0)
                        return -1;
                }
            }catch(IndexOutOfBoundsException e){
                return 1;
            }
        }
    }
    else return (left &gt; right)?1:-1;
    return 0;
}
</code></pre>

<p>I check whether <code>this.count</code> is equal to <code>o.count</code> and if not I begin to compare every element of arraylists. But if it is not equal then I compare <code>left</code> and <code>right</code>.</p>

<p>But I don't understand why it throws such exception. Where is the problem?</p>

<pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeHi(Unknown Source)
at java.util.ComparableTimSort.mergeAt(Unknown Source)
at java.util.ComparableTimSort.mergeCollapse(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.ComparableTimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
    at task.Main.main(Main.java:69)
</code></pre>

<p><code>Main.java: 69</code> is where <code>Collections.sort</code> invoked`.</p>
