Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 537394 - Comparison method violates its general contract [Open Resource dialog]
Summary: Comparison method violates its general contract [Open Resource dialog]
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.9 M2   Edit
Assignee: Andrey Loskutov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 531332
Blocks:
  Show dependency tree
 
Reported: 2018-07-25 16:48 EDT by Mchael Pujos CLA
Modified: 2018-07-29 09:16 EDT (History)
3 users (show)

See Also:


Attachments
org.eclipse.ui.workbench_3.111.0.v20180524-1156 (3.42 MB, application/x-java-archive)
2018-07-27 14:47 EDT, Lucas Bullen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mchael Pujos CLA 2018-07-25 16:48:47 EDT
Typinng some search characters in the "Open Resource" dialog (CTRL-SHIFT-R), I suddently got a "Comparison method violates its general contract!" error popup.
Here's the stack trace:

!ENTRY org.eclipse.core.jobs 4 2 2018-07-25 22:38:39.711
!MESSAGE An internal error occurred during: "Items filtering".
!STACK 0
java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(Unknown Source)
	at java.util.TimSort.mergeAt(Unknown Source)
	at java.util.TimSort.mergeForceCollapse(Unknown Source)
	at java.util.TimSort.sort(Unknown Source)
	at java.util.Arrays.sort(Unknown Source)
	at java.util.ArrayList.sort(Unknown Source)
	at java.util.Collections$SynchronizedList.sort(Unknown Source)
	at java.util.Collections.sort(Unknown Source)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.getSortedItems(FilteredItemsSelectionDialog.java:2701)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.rememberResult(FilteredItemsSelectionDialog.java:2714)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.filterContent(FilteredItemsSelectionDialog.java:2054)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.internalRun(FilteredItemsSelectionDialog.java:1998)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.doRun(FilteredItemsSelectionDialog.java:1970)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.run(FilteredItemsSelectionDialog.java:1957)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
Comment 1 Dani Megert CLA 2018-07-26 05:16:32 EDT
What's the build ID (Help > About Eclipse)?
Comment 2 Mchael Pujos CLA 2018-07-26 05:38:29 EDT
Build id: 20180619-1200
Comment 3 Dani Megert CLA 2018-07-26 08:55:02 EDT
Lucas, can you take a look?
Comment 4 Lucas Bullen CLA 2018-07-26 08:56:16 EDT
Yup. Do you remember what you were typing/what files you had in your workspace?
Comment 5 Mchael Pujos CLA 2018-07-26 09:03:24 EDT
I think I typed some random characters as I was not looking specifically something but was playing wihth the feature. Also I think it happened after several searches in the same dialog.

Interestingly, I managed to reproduce it after a few searches and agin on random characters after just about 1 minute (these time it is "Cache Refresh"):

!ENTRY org.eclipse.core.jobs 4 2 2018-07-26 14:58:06.641
!MESSAGE An internal error occurred during: "Cache refresh".
!STACK 0
java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(Unknown Source)
	at java.util.TimSort.mergeAt(Unknown Source)
	at java.util.TimSort.mergeForceCollapse(Unknown Source)
	at java.util.TimSort.sort(Unknown Source)
	at java.util.Arrays.sort(Unknown Source)
	at java.util.ArrayList.sort(Unknown Source)
	at java.util.Collections$SynchronizedList.sort(Unknown Source)
	at java.util.Collections.sort(Unknown Source)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.getSortedItems(FilteredItemsSelectionDialog.java:2701)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.getFilteredItems(FilteredItemsSelectionDialog.java:2840)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.reloadCache(FilteredItemsSelectionDialog.java:2774)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.reloadCache(FilteredItemsSelectionDialog.java:969)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$RefreshCacheJob.run(FilteredItemsSelectionDialog.java:1456)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
 

I'm going to check if I can reproduce it reliably and report.

My workspace is huge with about 60 opened projects, mostly Java and xml files.
Comment 6 Lucas Bullen CLA 2018-07-26 09:05:12 EDT
Ok this helps, I'll get to this later today.
Comment 7 Mchael Pujos CLA 2018-07-26 09:18:21 EDT
Ok, I reproduced it 5 times in a row, each crash happening 3-4 searches appart from the other. Searches making it crash seems random: can be 3 letters or just even 1 letter so I so not think it is related to the search term.
It's really non deterministic: sometimes there is no crash doing many searches for 1 or 2 minutes then you get a few crashes in quick succession... 
It's possible you can reprod it with a huge workspace, issuing fast searches in succession, using backspace to clear text. I've also seen it crash with the search textfield empty !
Comment 8 Mchael Pujos CLA 2018-07-26 09:25:48 EDT
I know can reproduce it very easily seaching alternatively for "cd" and "ds"

That is, typing:

c
d
backspace
backspace
d
s
backspace
backspace
c
d
...

These 2 searches have many results. 

The crash never happens if I alternate search of just 1 char: "c" and "d".
Comment 9 Lucas Bullen CLA 2018-07-26 09:38:15 EDT
After making quite the typing storm was able to replicate issue in I20180725-2000. Looking for solution.
Comment 10 Eclipse Genie CLA 2018-07-26 10:49:40 EDT
New Gerrit change created: https://git.eclipse.org/r/126669
Comment 11 Lucas Bullen CLA 2018-07-26 10:51:31 EDT
@Mchael would you be able to test the patch with your workspace since you are able to more consistently cause the flaw?
Comment 12 Mchael Pujos CLA 2018-07-26 10:54:24 EDT
I can test it if you provide me an updated jar that I can temporily replace in my Photon install. Not too keen on loading my workspace on a full newer Eclipse version.
Comment 13 Lucas Bullen CLA 2018-07-26 11:26:04 EDT
Don't know if that will work as I am unable to get the same build as you (feel free to correct me @Dani).

You could download the patch and test it in a child eclipse then import the same projects as your current workspace to test it
Comment 14 Mchael Pujos CLA 2018-07-26 11:41:07 EDT
I spent a lot of time migrating this rather complex workspace from Mars to Photon recently and do not want to import it in another version in fear of possibly breaking stuff.
Comment 15 Dani Megert CLA 2018-07-27 03:46:25 EDT
(In reply to Lucas Bullen from comment #13)
> Don't know if that will work as I am unable to get the same build as you
> (feel free to correct me @Dani).

You would have to create the plug-in JAR and then replace the version in the manifest and the JAR name with the one from Michael. That should work.
Comment 16 Lucas Bullen CLA 2018-07-27 12:54:18 EDT
@Mchael, can you go to your eclipse/plugins/ folder and tell my what the name of your org.eclipse.ui.workbench_3.112.0.v{date}.jar file is so I can create the jar?
Comment 17 Mchael Pujos CLA 2018-07-27 14:32:35 EDT
It's current Photon stable release (notice 3.111 instead of 3.112):

org.eclipse.ui.workbench_3.111.0.v20180524-1156.jar
Comment 18 Lucas Bullen CLA 2018-07-27 14:47:40 EDT
Created attachment 275166 [details]
org.eclipse.ui.workbench_3.111.0.v20180524-1156

Give that a try.
Comment 19 Mchael Pujos CLA 2018-07-27 17:09:44 EDT
Lucas,

The crash is still happening easily with the new version, alternating searches for cd and df.
I've triple checked that your updated jar was used, also confirmed with Collection.sort() being called at line 2699 (while 2701 in initial report).


///

!ENTRY org.eclipse.core.jobs 4 2 2018-07-27 22:56:38.697
!MESSAGE An internal error occurred during: "Items filtering".
!STACK 0
java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(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.Arrays.sort(Unknown Source)
	at java.util.ArrayList.sort(Unknown Source)
	at java.util.Collections$SynchronizedList.sort(Unknown Source)
	at java.util.Collections.sort(Unknown Source)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.getSortedItems(FilteredItemsSelectionDialog.java:2699)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$ContentProvider.rememberResult(FilteredItemsSelectionDialog.java:2712)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.filterContent(FilteredItemsSelectionDialog.java:2052)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.internalRun(FilteredItemsSelectionDialog.java:1996)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.doRun(FilteredItemsSelectionDialog.java:1968)
	at org.eclipse.ui.dialogs.FilteredItemsSelectionDialog$FilterJob.run(FilteredItemsSelectionDialog.java:1955)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:60)
Comment 20 Dani Megert CLA 2018-07-28 09:20:45 EDT
(In reply to Mchael Pujos from comment #19)
> Lucas,
> 
> The crash is still happening easily with the new version, alternating
> searches for cd and df.

Thanks for testing the fix Mchael.

Lucas, maybe you print something to the console with your next fix, so that we are 100% sure the fixed plug-in was used.
Comment 21 Eclipse Genie CLA 2018-07-29 03:18:33 EDT
New Gerrit change created: https://git.eclipse.org/r/126732
Comment 22 Andrey Loskutov CLA 2018-07-29 03:34:12 EDT
(In reply to Eclipse Genie from comment #21)
> New Gerrit change created: https://git.eclipse.org/r/126732

This should fix it. The code used *volatile* search patterns during sort, so if pattern changed while sort was in progress => kaboom.

Can be easily reproduced in debugger by modifying the code in the way that it throws exception if the pattern we saw at the comparator creation was not the same we see at compare() time.