Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison method violates its general contract! -> Java 1.7 bug #451

Closed
LevelX2 opened this issue Jul 10, 2014 · 11 comments
Closed

Comparison method violates its general contract! -> Java 1.7 bug #451

LevelX2 opened this issue Jul 10, 2014 · 11 comments
Labels

Comments

@LevelX2
Copy link
Contributor

@LevelX2 LevelX2 commented Jul 10, 2014

http://www.slightlymagic.net/forum/viewtopic.php?f=70&t=14709#p154924
When i played genesis Wave with x= 23 and i put a lot of card in play, an error appears.
error genesis wave

at mage.client.game.HelperPanel.setState(HelperPanel.java:146)
at mage.client.game.HelperPanel$2.actionPerformed(HelperPanel.java:113)

java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(Unknown Source)
at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(Unknown Source)
at java.awt.Component.getNextFocusCandidate(Unknown Source)
at java.awt.Component.transferFocus(Unknown Source)
at java.awt.Component.hide(Unknown Source)
at javax.swing.JComponent.hide(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at javax.swing.JComponent.setVisible(Unknown Source)
at mage.client.game.HelperPanel.setState(HelperPanel.java:146)
at mage.client.game.HelperPanel$2.actionPerformed(HelperPanel.java:113)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.

@magenoxx
Copy link
Member

@magenoxx magenoxx commented Jul 11, 2014

I couldn't reproduce it and we see it is some bug in Swing (this type of exceptions happens on sorting and HelperPanel doesn't sort anything).

Then I found it is a bug in Java 7:
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7075600

What they advise:
As a workaround, set java.util.Arrays.useLegacyMergeSort system property to true.

If player experiencing such exception over and over, he/she may run Mage.Client with -Djava.util.Arrays.useLegacyMergeSort=true

Also some advices can be found here:
http://stackoverflow.com/questions/13575224/comparison-method-violates-its-general-contract-timsort-and-gridlayout

@magenoxx
Copy link
Member

@magenoxx magenoxx commented Jul 11, 2014

Suggesting to close the bug as it is not a bug of XMage.

@LevelX2 LevelX2 added the bug label Jul 15, 2014
@LevelX2 LevelX2 closed this Aug 14, 2014
@LevelX2 LevelX2 reopened this Aug 14, 2014
@LevelX2 LevelX2 changed the title Genesis Wave with x= 23 -> Comparison method violates its general contract! Comparison method violates its general contract! -> Java 1.7 bug Aug 14, 2014
@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Aug 14, 2014

Makes it sense that we set the useLegacyMergeSort parameter in XMage by default?
Mage.Client with -Djava.util.Arrays.useLegacyMergeSort=true

@magenoxx
Copy link
Member

@magenoxx magenoxx commented Aug 14, 2014

what is drawback for using it?

@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Aug 14, 2014

Found nothing specific about drawbacks yet.
Forge crew had the same problem some time ago.
http://www.slightlymagic.net/forum/viewtopic.php?t=7268

I guess we have to test it. I will set it in the client main class to avoid more options for the start script and commit the change.
If it won't fix it or has big drawbacks, we have to look again.

@LevelX2 LevelX2 closed this in 175280b Aug 14, 2014
@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Aug 22, 2014

@LevelX2 LevelX2 reopened this Aug 22, 2014
@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Aug 24, 2014

Seems to be the same bug source
But I guess it can also be caused by not using invokeLater methods.

http://stackoverflow.com/questions/16866535/swing-components-mergesort-error

    at java.util.TimSort.mergeLo(Unknown Source)
    at java.util.TimSort.mergeAt(Unknown Source)
    at java.util.TimSort.mergeCollapse(Unknown Source)
    at java.util.TimSort.sort(Unknown Source)
    at java.util.TimSort.sort(Unknown Source)
    at java.util.Arrays.sort(Unknown Source)
    at java.util.Collections.sort(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(Unknown Source)
    at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(Unknown Source)
    at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(Unknown Source)
    at java.awt.Component.getNextFocusCandidate(Unknown Source)
    at java.awt.Component.transferFocus(Unknown Source)
    at java.awt.Component.hide(Unknown Source)
    at javax.swing.JComponent.hide(Unknown Source)
    at java.awt.Component.show(Unknown Source)
    at java.awt.Component.setVisible(Unknown Source)
    at javax.swing.JComponent.setVisible(Unknown Source)

    at mage.client.game.HelperPanel.setState(HelperPanel.java:146)
    at mage.client.game.HelperPanel$2.actionPerformed(HelperPanel.java:113)

        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
@emerald000
Copy link
Contributor

@emerald000 emerald000 commented Aug 27, 2014

Had it happen on the development version. Here's the error report:

FATAL 2014-08-27 18:22:17,044 =>[AWT-EventQueue-0] EDTExceptionHandler.handle
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:773)
at java.util.TimSort.mergeAt(TimSort.java:510)
at java.util.TimSort.mergeCollapse(TimSort.java:437)
at java.util.TimSort.sort(TimSort.java:241)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTraversalPolicy.java:136)
at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(SortingFocusTraversalPolicy.java:110)
at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(SortingFocusTraversalPolicy.java:282)
at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(LayoutFocusTraversalPolicy.java:106)
at java.awt.Component.getNextFocusCandidate(Component.java:7905)
at java.awt.Component.transferFocus(Component.java:7873)
at java.awt.Component.hide(Component.java:1696)
at javax.swing.JComponent.hide(JComponent.java:5576)
at java.awt.Component.show(Component.java:1656)
at java.awt.Component.setVisible(Component.java:1606)
at javax.swing.JComponent.setVisible(JComponent.java:2641)
at mage.client.game.HelperPanel.setState(HelperPanel.java:193)
at mage.client.game.HelperPanel$2$2$2.run(HelperPanel.java:133)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Aug 27, 2014

Don't know if this will solve the problem. But the setProperty was performed probably too late, as already swing compnents were used.
So there is still hope it works NOW.

@trintin
Copy link

@trintin trintin commented Aug 29, 2014

In mageclient.log I got this:

at java.awt.EventDispatchThread.run(Unknown Source)
FATAL 2014-08-29 19:53:02,350 =>[AWT-EventQueue-0] EDTExceptionHandler.handle
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getFocusTraversalCycle(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getDefaultComponent(Unknown Source)
at javax.swing.JDesktopPane$1.getDefaultComponent(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getComponentDownCycle(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getFirstComponent(Unknown Source)
at javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(Unknown Source)
at javax.swing.SortingFocusTraversalPolicy.getDefaultComponent(Unknown Source)
at java.awt.FocusTraversalPolicy.getInitialComponent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.SequencedEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

@LevelX2
Copy link
Contributor Author

@LevelX2 LevelX2 commented Sep 21, 2014

No more reports of this problem. Workaround seems to work now.

@LevelX2 LevelX2 closed this Sep 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants