JPL-IMCE / gov.nasa.jpl.imce.oml.converters

Converters among supported representations of OML models (textual, owl2-dl+swrl, tabular)
2 stars 1 forks source link

Conversion fails with default TimSort sorting algorithm #52

Closed sjiherzig closed 6 years ago

sjiherzig commented 6 years ago

When testing version 0.9.3 of the converter, it failed with the following exception:

LMC-051695:tmp20180215 sherzig$ OMLConverters/bin/omlConverter text -c ontologies/oml.catalog.xml -out ontologies-converted
18/02/22 16:23:50 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
conversion=ConversionCommandFromOMLTextualSyntax
# => 1259 OML files to convert...
# Loaded all OML resources (no EcoreUtil.resolveAll!).
### 1 Conversion Errors! ###
Comparison method violates its general contract!
java.lang.IllegalArgumentException: Comparison method violates its general contract!
    at java.util.TimSort.mergeHi(TimSort.java:899)
    at java.util.TimSort.mergeAt(TimSort.java:516)
    at java.util.TimSort.mergeCollapse(TimSort.java:441)
    at java.util.TimSort.sort(TimSort.java:245)
    at java.util.Arrays.sort(Arrays.java:1438)
    at scala.collection.SeqLike$class.sorted(SeqLike.scala:648)
    at scala.collection.AbstractSeq.sorted(Seq.scala:41)
    at scala.collection.SeqLike$class.sortWith(SeqLike.scala:601)
    at scala.collection.AbstractSeq.sortWith(Seq.scala:41)
    at gov.nasa.jpl.imce.oml.resolver.GraphUtilities$.hierarchicalTopologicalSort(GraphUtilities.scala:109)
    at gov.nasa.jpl.imce.oml.resolver.GraphUtilities$.hierarchicalTopologicalSort(GraphUtilities.scala:89)
    at gov.nasa.jpl.imce.oml.resolver.ResolverUtilities$$anonfun$sortExtents$2$$anonfun$apply$12.apply(ResolverUtilities.scala:138)
    at gov.nasa.jpl.imce.oml.resolver.ResolverUtilities$$anonfun$sortExtents$2$$anonfun$apply$12.apply(ResolverUtilities.scala:116)
    at scalaz.$bslash$div.flatMap(Either.scala:135)
...

This is an issue with Java's default sorting algorithm (TimSort) that has replaced MergeSort in Java 6. Defaulting back to MergeSort does the trick:

-Djava.util.Arrays.useLegacyMergeSort=true

Suggested fix is to add this to the entry point of the converter:

System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
NicolasRouquette commented 6 years ago

This has implications in several OML libraries.