AdamaJava / adamajava

Other
14 stars 4 forks source link

fix(q3tiledaligner): bug in comparator caused IllegalArgumentException #326

Closed holmeso closed 1 year ago

holmeso commented 1 year ago

Description

When sorting IntLongPair objects in a list, the comparator was ignoring the case where they could be equal. In certain circumstances this will throw an IllegalArgumentException "Comparison method violates its general contract!"

TARecordUtil.getBestILPFromList method had a lambda expression that sorted a list of IntLongPair objects. It would not return 0 (the presumption being that you would never find 2 "equal" IntLongPair objects).

This caused the problem when comparing the following 2 objects:

IntLongPair ilp1 = new IntLongPair(1507329, 4611878433244640844l);
IntLongPair ilp2 = new IntLongPair(1507329, 4611878433244640646l);

compare(ilp1, ilp2) returns 1 compare(ilp2, ilp1)also returns 1 This violates the general contract.

The fix was to return 0 when 2 IntLongPair objects are deemed "equal" (as they are in this case)

Also changed here is the compareTo method in BLATRecord which now no longer throws a NPE when comparing records that have a null name. Some unit tests accompany this change.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Additional unit test has been added. Updated code runs (without error) against sequence that caused initial IllegalArgumentException

Are WDL Updates Required?

No

Checklist: