Program: 13761
Project: 13761
Buggy source:
public int writePairedSAMRecordToContext(SAMRecord sam,boolean useCompact) throws IOException, InterruptedException {
  int count=0;
  int read1Ref=sam.getReferenceIndex();
  int read2Ref=sam.getMateReferenceIndex();
  if (!sam.getReadUnmappedFlag() && (read1Ref == read2Ref || keepChrSplitPairs) && (read1Ref > 0 || read2Ref > 0)) {
    context.getCounter(HalvadeCounters.OUT_BWA_READS).increment(1);
    writableRecord.set(sam);
    int[] keys=new int[4];
    int readLength=sam.getReadLength();
    int beginpos1=sam.getAlignmentStart();
    int beginpos2=sam.getMateAlignmentStart();
    int keyrange_start=0;
    int keyrange_end=4;
    if (read1Ref > 0) {
      keys[0]=splitter.getKey(splitter.getRegion(beginpos1,read1Ref),read1Ref);
      if (splitter.checkUpperBound(beginpos1 + readLength,read1Ref))       keys[1]=splitter.getKey(splitter.getRegion(beginpos1 + readLength,read1Ref),read1Ref);
 else       keys[1]=keys[0];
    }
 else     keyrange_start=2;
    if (read2Ref > 0) {
      keys[2]=splitter.getKey(splitter.getRegion(beginpos2,read2Ref),read2Ref);
      if (splitter.checkUpperBound(beginpos2 + readLength,read2Ref))       keys[3]=splitter.getKey(splitter.getRegion(beginpos2 + readLength,read2Ref),read2Ref);
 else       keys[3]=keys[2];
    }
 else     keyrange_end=2;
    Arrays.sort(keys);
    if (keyrange_start != keyrange_end) {
      if (useCompact) {
        writeableCompactRegion.setRegion(keys[keyrange_start],beginpos1);
        context.write(writeableCompactRegion,stub);
      }
 else {
        writableRegion.setChromosomeRegion(read1Ref,beginpos1,keys[keyrange_start]);
        context.write(writableRegion,writableRecord);
      }
      count++;
      for (int i=keyrange_start + 1; i < keyrange_end; i++) {
        if (keys[i] != keys[i - 1]) {
          context.getCounter(HalvadeCounters.OUT_OVERLAPPING_READS).increment(1);
          if (useCompact) {
            writeableCompactRegion.setRegion(keys[i],beginpos1);
            context.write(writeableCompactRegion,stub);
          }
 else {
            writableRegion.setChromosomeRegion(read1Ref,beginpos1,keys[i]);
            context.write(writableRegion,writableRecord);
          }
          count++;
        }
      }
    }
  }
 else {
    if (sam.getReadUnmappedFlag())     context.getCounter(HalvadeCounters.OUT_UNMAPPED_READS).increment(1);
 else     context.getCounter(HalvadeCounters.OUT_DIFF_CHR_READS).increment(1);
  }
  return count;
}

Fixed version (ground truth):
public int writePairedSAMRecordToContext(SAMRecord sam,boolean useCompact) throws IOException, InterruptedException {
  int count=0;
  int read1Ref=sam.getReferenceIndex();
  int read2Ref=sam.getMateReferenceIndex();
  if (!sam.getReadUnmappedFlag() && (read1Ref == read2Ref || keepChrSplitPairs) && (read1Ref >= 0 || read2Ref >= 0)) {
    context.getCounter(HalvadeCounters.OUT_BWA_READS).increment(1);
    writableRecord.set(sam);
    ArrayList<Integer> keys=new ArrayList<>();
    int readLength=sam.getReadLength();
    int beginpos1=sam.getAlignmentStart();
    int beginpos2=sam.getMateAlignmentStart();
    if (read1Ref >= 0) {
      keys.add(splitter.getKey(splitter.getRegion(beginpos1,read1Ref),read1Ref));
      keys.add(splitter.getKey(splitter.getRegion(beginpos1 + readLength,read1Ref),read1Ref));
    }
    if (read2Ref >= 0) {
      keys.add(splitter.getKey(splitter.getRegion(beginpos2,read2Ref),read2Ref));
      keys.add(splitter.getKey(splitter.getRegion(beginpos2 + readLength,read2Ref),read2Ref));
    }
    Set<Integer> mySet=new HashSet<>(keys);
    Iterator<Integer> it=mySet.iterator();
    while (it.hasNext()) {
      int key=it.next();
      if (useCompact) {
        writeableCompactRegion.setRegion(key,beginpos1);
        context.write(writeableCompactRegion,stub);
      }
 else {
        writableRegion.setChromosomeRegion(read1Ref,beginpos1,key);
        context.write(writableRegion,writableRecord);
      }
      count++;
    }
  }
 else {
    if (sam.getReadUnmappedFlag())     context.getCounter(HalvadeCounters.OUT_UNMAPPED_READS).increment(1);
 else     context.getCounter(HalvadeCounters.OUT_DIFF_CHR_READS).increment(1);
  }
  return count;
}