[Building Sakai] Java 7 and Sakai comparators

Hall, David (dmh2w) dmh2w at eservices.virginia.edu
Tue Jun 18 12:54:15 PDT 2013


We recently upgraded our production Sakai instance to Sakai 2.9 at the University of Virginia, and as part of our upgrade, switched to Tomcat 7 and Java 7. We were using Java 6 with our previous Sakai installation (2.8). Shortly after going live with 2.9, we began to receive isolated reports of users being unable to access the Resources tool in their worksites. This bug occurred with some worksites, but not others. The relevant portion of the stack trace was:

caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.TimSort.mergeHi(TimSort.java:868)
    at java.util.TimSort.mergeAt(TimSort.java:485)
    at java.util.TimSort.mergeForceCollapse(TimSort.java:426)
    at java.util.TimSort.sort(TimSort.java:223)
    at java.util.TimSort.sort(TimSort.java:173)
    at java.util.Arrays.sort(Arrays.java:659)
    at java.util.Collections.sort(Collections.java:217)
    at org.sakaiproject.content.tool.ListItem.getListItem(ListItem.java:275)
    at org.sakaiproject.content.tool.ResourcesAction.buildListContext(ResourcesAction.java:4314)
    at org.sakaiproject.content.tool.ResourcesAction.buildMainPanelContext(ResourcesAction.java:4625)

We discovered that Java 7 implemented a new sort routine that strictly validates comparators. While Java 6 silently ignored issues with comparators not honoring transitivity etc, Java 7 throws an exception. Some of the custom comparators defined in Sakai code do not adhere strictly to spec, and this was the cause of the Resources failure. We've opened https://jira.sakaiproject.org/browse/KNL-1083 to track this issue. The overall fix will probably be to go through each custom comparator in Sakai and ensure it is well-behaved by Java 7 standards. It's worth noting that https://jira.sakaiproject.org/browse/MSGCNTR-810 describes the same error within the Message Center tool (and fixes the particular comparator at issue).

There is a property that can be set to force Java 7 to use the legacy sort routine from Java 6. As a workaround for this issue in the short term, we've set the JVM property

-Djava.util.Arrays.useLegacyMergeSort=true

and this solved our issues. The new Java 7 sort routine was supposed to offer some performance improvements, but we've found the legacy sort to work fine for us in production. Just wanted to make anyone who may be using Java 7 with Sakai aware of this issue.

Thanks,
Matthew
University of Virginia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20130618/099c74c8/attachment.html 


More information about the sakai-dev mailing list