Prophetrouter exception -- the one Simulator

Source: Internet
Author: User

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 ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.