samtools / htsjdk

A Java API for high-throughput sequencing data (HTS) formats.
http://samtools.github.io/htsjdk/
283 stars 242 forks source link

VCFHeader shouldn't allow multiple VCFContigHeaderLines with the same contig index #1573

Open cmnbroad opened 2 years ago

cmnbroad commented 2 years ago

VCFHeader has no guard against multiple contig header lines with the same contig index. Also VCFContigHeaderLine has a compareTo implementation that ignores everything except for contigIndex, which makes it inconsistent with both equals and hashCode.

Set implementations that use a comparator, such as TreeSet, treat two VCFContigHeaderLine as equal if they have the same contig index, which is different than other non-comparator based sets. This results in various inconsistencies when two lines with the same index are included in a header (which can happen when merging headers, or manually creating headers):