Page 1 of 1

"Comparison Method violates it's general contract!" Crash

PostPosted: 12 Jun 2012, 20:32
by Hellfish
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:
  • 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.

Re: "Comparison Method violates it's general contract!" Cras

PostPosted: 12 Jun 2012, 21:00
by friarsol
Hellfish 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.
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 slouch

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).

Re: "Comparison Method violates it's general contract!" Cras

PostPosted: 13 Jun 2012, 13:07
by Max mtg
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.

Re: "Comparison Method violates it's general contract!" Cras

PostPosted: 13 Jun 2012, 19:24
by Hellfish
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. :)

Re: "Comparison Method violates it's general contract!" Cras

PostPosted: 14 Jun 2012, 05:14
by moomarc
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. :)
now we just need someone with java 1.7 to playtest it and see if it fixes those bugs.