Program: 30642
Project: 30642
Buggy source:
/** 
 * Combines multiple SAM/BAM files into one. 
 */
@Override protected int doWork(){
  boolean matchedSortOrders=true;
  final List<SAMFileReader> readers=new ArrayList<SAMFileReader>();
  final List<SAMFileHeader> headers=new ArrayList<SAMFileHeader>();
{
    SAMSequenceDictionary dict=null;
    for (    final File inFile : INPUT) {
      IoUtil.assertFileIsReadable(inFile);
      final SAMFileReader in=new SAMFileReader(inFile);
      readers.add(in);
      headers.add(in.getFileHeader());
      if (dict == null) {
        dict=in.getFileHeader().getSequenceDictionary();
      }
 else       if (dict.equals(in.getFileHeader().getSequenceDictionary())) {
        in.getFileHeader().setSequenceDictionary(dict);
      }
      matchedSortOrders=matchedSortOrders && in.getFileHeader().getSortOrder() == SORT_ORDER;
    }
  }
  IoUtil.assertFileIsWritable(OUTPUT);
  final boolean presorted;
  final SAMFileHeader.SortOrder headerMergerSortOrder;
  final boolean mergingSamRecordIteratorAssumeSorted;
  if (matchedSortOrders || SORT_ORDER == SAMFileHeader.SortOrder.unsorted || ASSUME_SORTED) {
    log.info("String_Node_Str");
    headerMergerSortOrder=SORT_ORDER;
    mergingSamRecordIteratorAssumeSorted=ASSUME_SORTED;
    presorted=true;
  }
 else {
    log.info("String_Node_Str" + TMP_DIR);
    headerMergerSortOrder=SAMFileHeader.SortOrder.unsorted;
    mergingSamRecordIteratorAssumeSorted=false;
    presorted=false;
  }
  final SamFileHeaderMerger headerMerger=new SamFileHeaderMerger(headerMergerSortOrder,headers,MERGE_SEQUENCE_DICTIONARIES);
  final MergingSamRecordIterator iterator=new MergingSamRecordIterator(headerMerger,readers,mergingSamRecordIteratorAssumeSorted);
  final SAMFileHeader header=headerMerger.getMergedHeader();
  for (  String comment : COMMENT) {
    header.addComment(comment);
  }
  header.setSortOrder(SORT_ORDER);
  final SAMFileWriter out=new SAMFileWriterFactory().makeSAMOrBAMWriter(header,presorted,OUTPUT);
  if (USE_THREADING) {
    final BlockingQueue<SAMRecord> queue=new ArrayBlockingQueue<SAMRecord>(10000);
    final AtomicBoolean producerSuccceeded=new AtomicBoolean(false);
    final AtomicBoolean consumerSuccceeded=new AtomicBoolean(false);
    Runnable producer=new Runnable(){
      public void run(){
        try {
          while (iterator.hasNext()) {
            queue.put(iterator.next());
          }
          producerSuccceeded.set(true);
        }
 catch (        InterruptedException ie) {
          throw new PicardException("String_Node_Str",ie);
        }
      }
    }
;
    Runnable consumer=new Runnable(){
      public void run(){
        try {
          long i=0;
          SAMRecord rec=null;
          while ((rec=queue.poll(15,TimeUnit.SECONDS)) != null) {
            out.addAlignment(rec);
            if (++i % PROGRESS_INTERVAL == 0)             log.info(i + "String_Node_Str");
          }
          consumerSuccceeded.set(true);
        }
 catch (        InterruptedException ie) {
          throw new PicardException("String_Node_Str",ie);
        }
      }
    }
;
    Thread producerThread=new Thread(producer);
    Thread consumerThread=new Thread(consumer);
    producerThread.start();
    consumerThread.start();
    try {
      consumerThread.join();
      producerThread.join();
    }
 catch (    InterruptedException ie) {
      throw new PicardException("String_Node_Str",ie);
    }
    if (!producerSuccceeded.get()) {
      throw new PicardException("String_Node_Str");
    }
    if (!consumerSuccceeded.get()) {
      throw new PicardException("String_Node_Str");
    }
  }
 else {
    for (long numRecords=1; iterator.hasNext(); ++numRecords) {
      final SAMRecord record=iterator.next();
      out.addAlignment(record);
      if (numRecords % PROGRESS_INTERVAL == 0) {
        log.info(numRecords + "String_Node_Str");
      }
    }
  }
  log.info("String_Node_Str");
  out.close();
  return 0;
}

Fixed version (ground truth):
/** 
 * Combines multiple SAM/BAM files into one. 
 */
@Override protected int doWork(){
  boolean matchedSortOrders=true;
  final List<SAMFileReader> readers=new ArrayList<SAMFileReader>();
  final List<SAMFileHeader> headers=new ArrayList<SAMFileHeader>();
{
    SAMSequenceDictionary dict=null;
    for (    final File inFile : INPUT) {
      IoUtil.assertFileIsReadable(inFile);
      final SAMFileReader in=new SAMFileReader(inFile);
      readers.add(in);
      headers.add(in.getFileHeader());
      if (dict == null) {
        dict=in.getFileHeader().getSequenceDictionary();
      }
 else       if (dict.equals(in.getFileHeader().getSequenceDictionary())) {
        in.getFileHeader().setSequenceDictionary(dict);
      }
      matchedSortOrders=matchedSortOrders && in.getFileHeader().getSortOrder() == SORT_ORDER;
    }
  }
  IoUtil.assertFileIsWritable(OUTPUT);
  final boolean presorted;
  final SAMFileHeader.SortOrder headerMergerSortOrder;
  final boolean mergingSamRecordIteratorAssumeSorted;
  if (matchedSortOrders || SORT_ORDER == SAMFileHeader.SortOrder.unsorted || ASSUME_SORTED) {
    log.info("String_Node_Str");
    headerMergerSortOrder=SORT_ORDER;
    mergingSamRecordIteratorAssumeSorted=ASSUME_SORTED;
    presorted=true;
  }
 else {
    log.info("String_Node_Str" + TMP_DIR);
    headerMergerSortOrder=SAMFileHeader.SortOrder.unsorted;
    mergingSamRecordIteratorAssumeSorted=false;
    presorted=false;
  }
  final SamFileHeaderMerger headerMerger=new SamFileHeaderMerger(headerMergerSortOrder,headers,MERGE_SEQUENCE_DICTIONARIES);
  final MergingSamRecordIterator iterator=new MergingSamRecordIterator(headerMerger,readers,mergingSamRecordIteratorAssumeSorted);
  final SAMFileHeader header=headerMerger.getMergedHeader();
  for (  String comment : COMMENT) {
    header.addComment(comment);
  }
  header.setSortOrder(SORT_ORDER);
  final SAMFileWriter out=new SAMFileWriterFactory().makeSAMOrBAMWriter(header,presorted,OUTPUT);
  if (USE_THREADING) {
    final BlockingQueue<SAMRecord> queue=new ArrayBlockingQueue<SAMRecord>(10000);
    final AtomicBoolean producerSuccceeded=new AtomicBoolean(false);
    final AtomicBoolean consumerSuccceeded=new AtomicBoolean(false);
    Runnable producer=new Runnable(){
      public void run(){
        try {
          while (iterator.hasNext()) {
            queue.put(iterator.next());
          }
          producerSuccceeded.set(true);
        }
 catch (        InterruptedException ie) {
          throw new PicardException("String_Node_Str",ie);
        }
      }
    }
;
    Runnable consumer=new Runnable(){
      public void run(){
        try {
          long i=0;
          while (!producerSuccceeded.get()) {
            SAMRecord rec=queue.poll(15,TimeUnit.SECONDS);
            if (rec != null) {
              out.addAlignment(rec);
              if (++i % PROGRESS_INTERVAL == 0)               log.info(i + "String_Node_Str");
            }
          }
          consumerSuccceeded.set(true);
        }
 catch (        InterruptedException ie) {
          throw new PicardException("String_Node_Str",ie);
        }
      }
    }
;
    Thread producerThread=new Thread(producer);
    Thread consumerThread=new Thread(consumer);
    producerThread.start();
    consumerThread.start();
    try {
      consumerThread.join();
      producerThread.join();
    }
 catch (    InterruptedException ie) {
      throw new PicardException("String_Node_Str",ie);
    }
    if (!producerSuccceeded.get()) {
      throw new PicardException("String_Node_Str");
    }
    if (!consumerSuccceeded.get()) {
      throw new PicardException("String_Node_Str");
    }
  }
 else {
    for (long numRecords=1; iterator.hasNext(); ++numRecords) {
      final SAMRecord record=iterator.next();
      out.addAlignment(record);
      if (numRecords % PROGRESS_INTERVAL == 0) {
        log.info(numRecords + "String_Node_Str");
      }
    }
  }
  log.info("String_Node_Str");
  out.close();
  return 0;
}