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.
[X] Bug fix (non-breaking change which fixes an issue)
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:
[X] My code follows the style guidelines of this project
[X] I have performed a self-review of my own code
[X] I have commented my code, particularly in hard-to-understand areas
[X] I have made corresponding changes to the documentation
[X] My changes generate no new warnings
[X] I have added tests that prove my fix is effective or that my feature works
[X] New and existing unit tests pass locally with my changes
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 ofIntLongPair
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:
compare(ilp1, ilp2)
returns 1compare(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 anull
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: