Author jamesmudd
Recipients jamesmudd, jeff.allen, stefan.richthofer, zyasoft
Date 2017-03-19.12:10:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I have carried on investigating this is a similar direction, and can confirm the issue is with Java's TimSort which is now the default sorting algorithm for objects. I now also have a pure java example of this issue attached (sorry its a bit messy, very quickly written). @Jeff your exactly right to see the list become "corrupted" you need the comparator to throw an exception while TimSort is doing a merge an example stack is:

	at test.TestSortJava$
	at test.TestSortJava$
	at java.util.TimSort.mergeLo(
	at java.util.TimSort.mergeAt(
	at java.util.TimSort.mergeCollapse(
	at java.util.TimSort.sort(
	at java.util.Arrays.sort(
	at java.util.ArrayList.sort(
	at java.util.Collections.sort(
	at test.TestSortJava.main(

I'm not clear on what the best fix is, the simplest option is to disable TimSort, which you can do by reverting to the legacy sort algorithm by setting the property -Djava.util.Arrays.useLegacyMergeSort=true see also
I'm not sure this is a workable fix for jython as you can't ensure this property will be set when embedded in other applications but its an option?

It might also be possible to cache and restore the list somehow if we know the sort has gone wrong, I could probably write a patch for that? This will slow down sorting as we will need to compare the items in the before and after lists to determine is we are seeing this issue but I think it would be robust? For large lists this could be bad.

There are also some bugs in Java around this e.g. (and linked) so maybe it's fixed in 9, and we should but ignore it till then? I'm not clear this is actually a Java bug though the behaviour of this case seems undefined.
Date User Action Args
2017-03-19 12:10:14jamesmuddsetmessageid: <>
2017-03-19 12:10:14jamesmuddsetrecipients: + jamesmudd, zyasoft, jeff.allen, stefan.richthofer
2017-03-19 12:10:14jamesmuddlinkissue2399 messages
2017-03-19 12:10:13jamesmuddcreate