"Comparison Method violates it's general contract!" Crash
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
5 posts
• Page 1 of 1
"Comparison Method violates it's general contract!" Crash
by Hellfish » 12 Jun 2012, 20:32
Just an infodump while I wrestle with the branch reintegration of AbilityWork.
This crash is a result of the stricter approach of Java 1.7 to non-transitive comparison methods (ie if A >= B and B >= C is true then A >= C should be true but isn't). The error isn't actually in our code but in Swing's LayoutFocusTraversalPolicy class, as I understand it, and is apparently a regression in 1.7 (1.5 apparently also had this problem, so 1.6 is the sweet-spot). LayoutFocusTraversalPolicy handles in which order UI components should recieve focus. The latest bug report I've found on this was closed as not reproducible.
Two solutions I've found in old threads and bug reports are:
This crash is a result of the stricter approach of Java 1.7 to non-transitive comparison methods (ie if A >= B and B >= C is true then A >= C should be true but isn't). The error isn't actually in our code but in Swing's LayoutFocusTraversalPolicy class, as I understand it, and is apparently a regression in 1.7 (1.5 apparently also had this problem, so 1.6 is the sweet-spot). LayoutFocusTraversalPolicy handles in which order UI components should recieve focus. The latest bug report I've found on this was closed as not reproducible.

Two solutions I've found in old threads and bug reports are:
- Setting the System Property "java.util.Arrays.useLegacyMergeSort" to true via System.setProperty(). Pros: Easily done. Cons: May create issues elsewhere, not 100% certain to fix the problem, more of a workaround than a fix.
- Writing one or (more likely) several custom FocusTraversalPolicies for each panel with multiple components. Pros: Likely more robust. Cons: Not sure how much work this would need (probably quite a bit), possibly overkill.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: "Comparison Method violates it's general contract!" Cras
by friarsol » 12 Jun 2012, 21:00
I'm not sure if changing to Merge Sort will create other issues, TimSort is faster, but that doesn't mean that Merge sort is a slouchHellfish wrote:Two solutions I've found in old threads and bug reports are:
- Setting the System Property "java.util.Arrays.useLegacyMergeSort" to true via System.setProperty(). Pros: Easily done. Cons: May create issues elsewhere, not 100% certain to fix the problem, more of a workaround than a fix.
- Writing one or (more likely) several custom FocusTraversalPolicies for each panel with multiple components. Pros: Likely more robust. Cons: Not sure how much work this would need (probably quite a bit), possibly overkill.
http://news.ycombinator.com/item?id=752677
We're probably better off using the Legacy Merge Sort until it makes sense to handling the traversal policies (if that's the right thing to do).
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: "Comparison Method violates it's general contract!" Cras
by Max mtg » 13 Jun 2012, 13:07
The largest collection to sort in our game is a collection of all the cards with as many as 20k records, so I don't think the "legacy" Merge sort would create any performance problem. To my mind, its completelly safe to set the mentioned property to true.
Single class for single responsibility.
- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: "Comparison Method violates it's general contract!" Cras
by Hellfish » 13 Jun 2012, 19:24
I went ahead and added the property setting to startup. If there is a problem it oughta rear it's ugly head before next beta. 

So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: "Comparison Method violates it's general contract!" Cras
by moomarc » 14 Jun 2012, 05:14
now we just need someone with java 1.7 to playtest it and see if it fixes those bugs.Hellfish wrote:I went ahead and added the property setting to startup. If there is a problem it oughta rear it's ugly head before next beta.
-Marc
-
moomarc - Pixel Commander
- Posts: 2091
- Joined: 04 Jun 2010, 15:22
- Location: Johannesburg, South Africa
- Has thanked: 371 times
- Been thanked: 372 times
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 27 guests