Prophetrouter may encounter the following problems:
Exception in thread "Main" 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. timsort. Sort (unknown source)
At java. util. arrays. Sort (unknown source)
At java. util. Collections. Sort (unknown source)
At routing. prophetrouter. tryothermessages (prophetrouter. Java: 241)
At routing. prophetrouter. Update (prophetrouter. Java: 201)
At CORE. dtnhost. Update (dtnhost. Java: 330)
At CORE. World. updatehosts (World. Java: 217)
At CORE. World. Update (World. Java: 186)
At gui. dtnsimgui. runsim (dtnsimgui. Java: 115)
At UI. dtnsimui. Start (dtnsimui. Java: 77)
At CORE. dtnsim. Main (dtnsim. Java: 92)
It is caused by tuplecomparator in prophetrouter. Java:
Private class tuplecomparator implements Comparator
<Tuple <message, connection >> {
Public int compare (tuple <message, connection> tuple1,
Tuple <message, connection> tuple2 ){
// Delivery probability of tuple1's message with tuple1's connection
Double p1 = (prophetrouter) tuple1.getvalue ().
Getothernode (gethost (). getrouter (). getpredfor (
Tuple1.getkey (). getto ());
//-"-Tuple2...
Double P2 = (prophetrouter) tuple2.getvalue ().
Getothernode (gethost (). getrouter (). getpredfor (
Tuple2.getkey (). getto ());
// Bigger probability shocould come first
If (P2-P1 = 0 ){
/* Equal probabilities-> let queue mode decide */
Return comparebyqueuemode (tuple1.getkey (), tuple2.getkey ());
}
Else if (P2-P1 <0 ){
Return-1;
}
Else {
Return 1;
}
}
}
Because:Java version. Java 1.7 is used.TimSort, AndTimsort found comparable violationComparableContractWill throw
Illegalargumentexception.
Similar to this question: http://stackoverflow.com/questions/6626437/why-does-my-compare-method-throw-exception-comparison-method-violates-its-gen
From http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source
Area: API: utilities
Synopsis: Updated sort behaviorArraysAndCollectionsMay throwIllegalArgumentException
Description: The Sorting Algorithm Usedjava.util.Arrays.sortAnd (indirectly)java.util.Collections.sortHas been replaced. The new sort implementation may throwIllegalArgumentExceptionIf it detectsComparableThat violatesComparableContract. The previous implementation silently ignored such a situation. If the previous behavior is desired, you can use the new system property,java.util.Arrays.useLegacyMergeSort, To restore previous mergesort behavior.
Nature of incompatibility: Behavioral
RFE: 6804124.
Therefore, make the following changes:
Add a line of code to the main function of the program:
System. setproperty ("Java. util. arrays. uselegacymergesort", "true ");