Program: 30638
Project: 30638
Buggy source:
protected int doWork(){
  IoUtil.assertFileIsReadable(INPUT);
  final SAMFileReader reader=new SAMFileReader(IoUtil.openFileForReading(INPUT));
  final Map<String,SAMRecord> firstSeenMates=new HashMap<String,SAMRecord>();
  final FastqWriterFactory factory=new FastqWriterFactory();
  final Map<SAMReadGroupRecord,List<FastqWriter>> writers=getWriters(reader.getFileHeader().getReadGroups(),factory);
  long count=0;
  for (  final SAMRecord currentRecord : reader) {
    if (currentRecord.getNotPrimaryAlignmentFlag() && !INCLUDE_NON_PRIMARY_ALIGNMENTS)     continue;
    if (currentRecord.getReadFailsVendorQualityCheckFlag() && !INCLUDE_NON_PF_READS)     continue;
    final List<FastqWriter> fq=writers.get(currentRecord.getReadGroup());
    if (currentRecord.getReadPairedFlag()) {
      final String currentReadName=currentRecord.getReadName();
      final SAMRecord firstRecord=firstSeenMates.remove(currentReadName);
      if (firstRecord == null) {
        firstSeenMates.put(currentReadName,currentRecord);
      }
 else {
        assertPairedMates(firstRecord,currentRecord);
        if (OUTPUT_PER_RG && fq.size() == 1) {
          fq.add(factory.newWriter(makeReadGroupFile(currentRecord.getReadGroup(),"String_Node_Str")));
        }
        final SAMRecord read1=currentRecord.getFirstOfPairFlag() ? currentRecord : firstRecord;
        final SAMRecord read2=currentRecord.getFirstOfPairFlag() ? firstRecord : currentRecord;
        writeRecord(read1,1,fq.get(0),READ1_TRIM,READ1_MAX_BASES_TO_WRITE);
        writeRecord(read2,2,fq.get(1),READ2_TRIM,READ2_MAX_BASES_TO_WRITE);
      }
    }
 else {
      writeRecord(currentRecord,null,fq.get(0),READ1_TRIM,READ1_MAX_BASES_TO_WRITE);
    }
    if (++count % 10000000 == 0) {
      log.info("String_Node_Str" + count + "String_Node_Str");
    }
  }
  reader.close();
  if (firstSeenMates.size() > 0) {
    throw new PicardException("String_Node_Str" + firstSeenMates.size() + "String_Node_Str");
  }
  for (  final List<FastqWriter> listOfWriters : writers.values()) {
    for (    final FastqWriter w : listOfWriters) {
      w.close();
    }
  }
  return 0;
}

Fixed version (ground truth):
protected int doWork(){
  IoUtil.assertFileIsReadable(INPUT);
  final SAMFileReader reader=new SAMFileReader(IoUtil.openFileForReading(INPUT));
  final Map<String,SAMRecord> firstSeenMates=new HashMap<String,SAMRecord>();
  final FastqWriterFactory factory=new FastqWriterFactory();
  final Map<SAMReadGroupRecord,List<FastqWriter>> writers=getWriters(reader.getFileHeader().getReadGroups(),factory);
  long count=0;
  for (  final SAMRecord currentRecord : reader) {
    if (currentRecord.getNotPrimaryAlignmentFlag() && !INCLUDE_NON_PRIMARY_ALIGNMENTS)     continue;
    if (currentRecord.getReadFailsVendorQualityCheckFlag() && !INCLUDE_NON_PF_READS)     continue;
    final List<FastqWriter> fq=writers.get(currentRecord.getReadGroup());
    if (currentRecord.getReadPairedFlag()) {
      final String currentReadName=currentRecord.getReadName();
      final SAMRecord firstRecord=firstSeenMates.remove(currentReadName);
      if (firstRecord == null) {
        firstSeenMates.put(currentReadName,currentRecord);
      }
 else {
        assertPairedMates(firstRecord,currentRecord);
        if (OUTPUT_PER_RG && fq.size() == 1) {
          fq.add(factory.newWriter(makeReadGroupFile(currentRecord.getReadGroup(),"String_Node_Str")));
        }
        final SAMRecord read1=currentRecord.getFirstOfPairFlag() ? currentRecord : firstRecord;
        final SAMRecord read2=currentRecord.getFirstOfPairFlag() ? firstRecord : currentRecord;
        writeRecord(read1,1,fq.get(0),READ1_TRIM,READ1_MAX_BASES_TO_WRITE);
        writeRecord(read2,2,fq.get(1),READ2_TRIM,READ2_MAX_BASES_TO_WRITE);
      }
    }
 else {
      writeRecord(currentRecord,null,fq.get(0),READ1_TRIM,READ1_MAX_BASES_TO_WRITE);
    }
    if (++count % 10000000 == 0) {
      log.info("String_Node_Str" + count + "String_Node_Str");
    }
  }
  reader.close();
  if (firstSeenMates.size() > 0) {
    throw new PicardException("String_Node_Str" + firstSeenMates.size() + "String_Node_Str");
  }
  final IdentityHashMap<FastqWriter,FastqWriter> seen=new IdentityHashMap<FastqWriter,FastqWriter>();
  for (  final List<FastqWriter> listOfWriters : writers.values()) {
    for (    final FastqWriter w : listOfWriters) {
      if (!seen.containsKey(w)) {
        w.close();
        seen.put(w,w);
      }
    }
  }
  return 0;
}