sweble / sweble-wikitext

The Sweble Wikitext Components module provides a parser for MediaWiki's wikitext and an engine trying to emulate the behavior of a MediaWiki.
http://sweble.org/sites/swc-devel/develop-latest/tooling/sweble/sweble-wikitext
70 stars 27 forks source link

"Comparison method violates its general contract" in VisitorLogic.sweepCache #49

Closed kno10 closed 7 years ago

kno10 commented 8 years ago
Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
        at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:744)
        at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:481)
        at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:406)
        at java.util.ComparableTimSort.sort(ComparableTimSort.java:213)
        at java.util.Arrays.sort(Arrays.java:1312)
        at de.fau.cs.osr.utils.visitor.VisitorLogic.sweepCache(VisitorLogic.java:225)
        at de.fau.cs.osr.utils.visitor.VisitorLogic.findVisit(VisitorLogic.java:205)
        at de.fau.cs.osr.utils.visitor.VisitorLogic.resolveAndVisit(VisitorLogic.java:105)

This is probably caused by multiple threads being used, and thus lastUse changing. The synchronization on sweepCache is not enough to prevent other threads from changing lastUse. It may be enough to just attempt to partially sort the targets to identify the least frequently used, rather than calling Arrays.sort. A quick select strategy may be worth trying. (Note: this bug likely doesn't appear in older Java versions, which did not use TimSort).

P.S. the osr-common repository, where this is supposed to be in, is currently empty.

kno10 commented 7 years ago

Migrated to: https://github.com/sweble/osr-common/issues/1