Program: 30668
Project: 30668
Buggy source:
protected int doWork(){
  boolean allQueryNameSorted=true;
  final List<SAMFileReader> readers=new ArrayList<SAMFileReader>();
  for (  final File f : INPUT) {
    IoUtil.assertFileIsReadable(f);
    SAMFileReader reader=new SAMFileReader(f);
    readers.add(new SAMFileReader(f));
    if (reader.getFileHeader().getSortOrder() != SortOrder.queryname)     allQueryNameSorted=false;
  }
  if (OUTPUT != null)   OUTPUT=OUTPUT.getAbsoluteFile();
  final boolean differentOutputSpecified=OUTPUT != null;
  if (differentOutputSpecified) {
    IoUtil.assertFileIsWritable(OUTPUT);
  }
 else   if (INPUT.size() != 1) {
    throw new PicardException("String_Node_Str");
  }
 else {
    final File soleInput=INPUT.get(0).getAbsoluteFile();
    final File dir=soleInput.getParentFile().getAbsoluteFile();
    try {
      IoUtil.assertFileIsWritable(soleInput);
      IoUtil.assertDirectoryIsWritable(dir);
      OUTPUT=File.createTempFile(soleInput.getName() + "String_Node_Str","String_Node_Str",dir);
    }
 catch (    IOException ioe) {
      throw new RuntimeIOException("String_Node_Str" + dir.getAbsolutePath());
    }
  }
  final PeekableIterator<SAMRecord> iterator;
  final SAMFileHeader header;
{
    Iterator<SAMRecord> tmp;
    if (INPUT.size() > 1) {
      final SamFileHeaderMerger merger=new SamFileHeaderMerger(readers,SortOrder.unsorted,false);
      tmp=new MergingSamRecordIterator(merger,false);
      header=merger.getMergedHeader();
    }
 else {
      tmp=readers.get(0).iterator();
      header=readers.get(0).getFileHeader();
    }
    if (allQueryNameSorted) {
      iterator=new PeekableIterator<SAMRecord>(tmp);
    }
 else {
      log.info("String_Node_Str");
      final SortingCollection<SAMRecord> sorter=SortingCollection.newInstance(SAMRecord.class,new BAMRecordCodec(header),new SAMRecordQueryNameComparator(),MAX_RECORDS_IN_RAM,TMP_DIR);
      while (tmp.hasNext()) {
        sorter.add(tmp.next());
      }
      iterator=new PeekableIterator<SAMRecord>(sorter.iterator());
      log.info("String_Node_Str");
    }
    final SortOrder outputSortOrder=SORT_ORDER == null ? readers.get(0).getFileHeader().getSortOrder() : SORT_ORDER;
    log.info("String_Node_Str" + outputSortOrder);
    header.setSortOrder(outputSortOrder);
  }
  final SAMFileWriter out=new SAMFileWriterFactory().makeSAMOrBAMWriter(header,header.getSortOrder() == SortOrder.queryname,OUTPUT);
  log.info("String_Node_Str");
  int count=0;
  while (iterator.hasNext()) {
    final SAMRecord rec1=iterator.next();
    final SAMRecord rec2=iterator.hasNext() ? iterator.peek() : null;
    if (rec2 != null && rec1.getReadName().equals(rec2.getReadName())) {
      iterator.next();
      SamPairUtil.setMateInfo(rec1,rec2,header);
      out.addAlignment(rec1);
      out.addAlignment(rec2);
      count+=2;
    }
 else {
      out.addAlignment(rec1);
      ++count;
    }
    if (count % 1000000 == 0) {
      log.info("String_Node_Str" + count + "String_Node_Str");
    }
  }
  if (header.getSortOrder() == SortOrder.queryname) {
    log.info("String_Node_Str");
  }
 else {
    log.info("String_Node_Str");
  }
  out.close();
  if (!differentOutputSpecified) {
    log.info("String_Node_Str");
    final File soleInput=INPUT.get(0).getAbsoluteFile();
    final File old=new File(soleInput.getParentFile(),soleInput.getName() + "String_Node_Str");
    if (!old.exists() && soleInput.renameTo(old)) {
      if (OUTPUT.renameTo(soleInput)) {
        if (!old.delete()) {
          log.warn("String_Node_Str" + old.getAbsolutePath());
          return 1;
        }
      }
 else {
        log.error("String_Node_Str" + soleInput.getAbsolutePath());
        log.error("String_Node_Str" + old.getAbsolutePath());
        log.error("String_Node_Str" + OUTPUT.getAbsolutePath());
        return 1;
      }
    }
 else {
      log.error("String_Node_Str" + soleInput.getAbsolutePath());
      if (!OUTPUT.delete()) {
        log.error("String_Node_Str" + OUTPUT.getAbsolutePath());
      }
      return 1;
    }
  }
  return 0;
}

Fixed version (ground truth):
protected int doWork(){
  boolean allQueryNameSorted=true;
  final List<SAMFileReader> readers=new ArrayList<SAMFileReader>();
  for (  final File f : INPUT) {
    IoUtil.assertFileIsReadable(f);
    SAMFileReader reader=new SAMFileReader(f);
    readers.add(new SAMFileReader(f));
    if (reader.getFileHeader().getSortOrder() != SortOrder.queryname)     allQueryNameSorted=false;
  }
  if (OUTPUT != null)   OUTPUT=OUTPUT.getAbsoluteFile();
  final boolean differentOutputSpecified=OUTPUT != null;
  if (differentOutputSpecified) {
    IoUtil.assertFileIsWritable(OUTPUT);
  }
 else   if (INPUT.size() != 1) {
    throw new PicardException("String_Node_Str");
  }
 else {
    final File soleInput=INPUT.get(0).getAbsoluteFile();
    final File dir=soleInput.getParentFile().getAbsoluteFile();
    try {
      IoUtil.assertFileIsWritable(soleInput);
      IoUtil.assertDirectoryIsWritable(dir);
      OUTPUT=File.createTempFile(soleInput.getName() + "String_Node_Str","String_Node_Str",dir);
    }
 catch (    IOException ioe) {
      throw new RuntimeIOException("String_Node_Str" + dir.getAbsolutePath());
    }
  }
  final PeekableIterator<SAMRecord> iterator;
  final SAMFileHeader header;
{
    Iterator<SAMRecord> tmp;
    if (INPUT.size() > 1) {
      final SamFileHeaderMerger merger=new SamFileHeaderMerger(readers,SortOrder.unsorted,false);
      tmp=new MergingSamRecordIterator(merger,false);
      header=merger.getMergedHeader();
    }
 else {
      tmp=readers.get(0).iterator();
      header=readers.get(0).getFileHeader();
    }
    if (allQueryNameSorted) {
      iterator=new PeekableIterator<SAMRecord>(tmp);
    }
 else {
      log.info("String_Node_Str");
      final SortingCollection<SAMRecord> sorter=SortingCollection.newInstance(SAMRecord.class,new BAMRecordCodec(header),new SAMRecordQueryNameComparator(),MAX_RECORDS_IN_RAM,TMP_DIR);
      while (tmp.hasNext()) {
        sorter.add(tmp.next());
      }
      iterator=new PeekableIterator<SAMRecord>(sorter.iterator());
      log.info("String_Node_Str");
    }
    final SortOrder outputSortOrder=SORT_ORDER == null ? readers.get(0).getFileHeader().getSortOrder() : SORT_ORDER;
    log.info("String_Node_Str" + outputSortOrder);
    header.setSortOrder(outputSortOrder);
  }
  final SAMFileWriter out=new SAMFileWriterFactory().makeSAMOrBAMWriter(header,header.getSortOrder() == SortOrder.queryname,OUTPUT);
  log.info("String_Node_Str");
  long count=0;
  while (iterator.hasNext()) {
    final SAMRecord rec1=iterator.next();
    final SAMRecord rec2=iterator.hasNext() ? iterator.peek() : null;
    if (rec2 != null && rec1.getReadName().equals(rec2.getReadName())) {
      iterator.next();
      SamPairUtil.setMateInfo(rec1,rec2,header);
      out.addAlignment(rec1);
      out.addAlignment(rec2);
      count+=2;
    }
 else {
      out.addAlignment(rec1);
      ++count;
    }
    if (count % 1000000 == 0) {
      log.info("String_Node_Str" + count + "String_Node_Str");
    }
  }
  if (header.getSortOrder() == SortOrder.queryname) {
    log.info("String_Node_Str");
  }
 else {
    log.info("String_Node_Str");
  }
  out.close();
  if (!differentOutputSpecified) {
    log.info("String_Node_Str");
    final File soleInput=INPUT.get(0).getAbsoluteFile();
    final File old=new File(soleInput.getParentFile(),soleInput.getName() + "String_Node_Str");
    if (!old.exists() && soleInput.renameTo(old)) {
      if (OUTPUT.renameTo(soleInput)) {
        if (!old.delete()) {
          log.warn("String_Node_Str" + old.getAbsolutePath());
          return 1;
        }
      }
 else {
        log.error("String_Node_Str" + soleInput.getAbsolutePath());
        log.error("String_Node_Str" + old.getAbsolutePath());
        log.error("String_Node_Str" + OUTPUT.getAbsolutePath());
        return 1;
      }
    }
 else {
      log.error("String_Node_Str" + soleInput.getAbsolutePath());
      if (!OUTPUT.delete()) {
        log.error("String_Node_Str" + OUTPUT.getAbsolutePath());
      }
      return 1;
    }
  }
  return 0;
}