Program: 17245
Project: 17245
Buggy source:
@Override public void flush() throws IOException {
  final String uniqueIdentifier=outputContext.getUniqueIdentifier();
  Path finalOutputFile=mapOutputFile.getOutputFileForWrite(0);
  Path finalIndexFile=mapOutputFile.getOutputIndexFileForWrite(0);
  LOG.info("String_Node_Str");
  span.end();
  merger.add(span.sort(sorter,comparator));
  spill();
  sortmaster.shutdown();
  largeBuffer=null;
  if (numSpills == 1) {
    final Path filename=mapOutputFile.getSpillFile(0);
    Path indexFilename=mapOutputFile.getSpillIndexFile(0);
    sameVolRename(filename,mapOutputFile.getOutputFileForWriteInVolume(filename));
    sameVolRename(indexFilename,mapOutputFile.getOutputIndexFileForWriteInVolume(indexFilename));
    return;
  }
  FSDataOutputStream finalOut=rfs.create(finalOutputFile,true,4096);
  TezMerger.considerFinalMergeForProgress();
  final TezSpillRecord spillRec=new TezSpillRecord(partitions);
  final ArrayList<TezSpillRecord> indexCacheList=new ArrayList<TezSpillRecord>();
  for (int i=0; i < numSpills; i++) {
    Path indexFilename=mapOutputFile.getSpillIndexFile(i);
    TezSpillRecord spillIndex=new TezSpillRecord(indexFilename,conf);
    indexCacheList.add(spillIndex);
  }
  for (int parts=0; parts < partitions; parts++) {
    List<Segment> segmentList=new ArrayList<Segment>(numSpills);
    for (int i=0; i < numSpills; i++) {
      Path spillFilename=mapOutputFile.getSpillFile(i);
      TezIndexRecord indexRecord=indexCacheList.get(i).getIndex(parts);
      Segment s=new Segment(conf,rfs,spillFilename,indexRecord.getStartOffset(),indexRecord.getPartLength(),codec,ifileReadAhead,ifileReadAheadLength,ifileBufferSize,true);
      segmentList.add(i,s);
    }
    int mergeFactor=this.conf.getInt(TezJobConfig.TEZ_RUNTIME_IO_SORT_FACTOR,TezJobConfig.DEFAULT_TEZ_RUNTIME_IO_SORT_FACTOR);
    boolean sortSegments=segmentList.size() > mergeFactor;
    TezRawKeyValueIterator kvIter=TezMerger.merge(conf,rfs,keyClass,valClass,codec,segmentList,mergeFactor,new Path(uniqueIdentifier),(RawComparator)ConfigUtils.getIntermediateOutputKeyComparator(conf),nullProgressable,sortSegments,null,spilledRecordsCounter,null,null);
    long segmentStart=finalOut.getPos();
    Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,spilledRecordsCounter,null);
    writer.setRLE(merger.needsRLE());
    if (combiner == null || numSpills < minSpillsForCombine) {
      TezMerger.writeFile(kvIter,writer,nullProgressable,TezJobConfig.DEFAULT_RECORDS_BEFORE_PROGRESS);
    }
 else {
      runCombineProcessor(kvIter,writer);
    }
    writer.close();
    final TezIndexRecord rec=new TezIndexRecord(segmentStart,writer.getRawLength(),writer.getCompressedLength());
    spillRec.putIndex(rec,parts);
  }
  spillRec.writeToFile(finalIndexFile,conf);
  finalOut.close();
  for (int i=0; i < numSpills; i++) {
    Path indexFilename=mapOutputFile.getSpillIndexFile(i);
    Path spillFilename=mapOutputFile.getSpillFile(i);
    rfs.delete(indexFilename,true);
    rfs.delete(spillFilename,true);
  }
}

Fixed version (ground truth):
@Override public void flush() throws IOException {
  final String uniqueIdentifier=outputContext.getUniqueIdentifier();
  Path finalOutputFile=mapOutputFile.getOutputFileForWrite(0);
  Path finalIndexFile=mapOutputFile.getOutputIndexFileForWrite(0);
  LOG.info("String_Node_Str");
  span.end();
  merger.add(span.sort(sorter,comparator));
  spill();
  sortmaster.shutdown();
  largeBuffer=null;
  if (numSpills == 1) {
    final Path filename=mapOutputFile.getSpillFile(0);
    Path indexFilename=mapOutputFile.getSpillIndexFile(0);
    sameVolRename(filename,mapOutputFile.getOutputFileForWriteInVolume(filename));
    sameVolRename(indexFilename,mapOutputFile.getOutputIndexFileForWriteInVolume(indexFilename));
    return;
  }
  FSDataOutputStream finalOut=rfs.create(finalOutputFile,true,4096);
  final TezSpillRecord spillRec=new TezSpillRecord(partitions);
  final ArrayList<TezSpillRecord> indexCacheList=new ArrayList<TezSpillRecord>();
  for (int i=0; i < numSpills; i++) {
    Path indexFilename=mapOutputFile.getSpillIndexFile(i);
    TezSpillRecord spillIndex=new TezSpillRecord(indexFilename,conf);
    indexCacheList.add(spillIndex);
  }
  for (int parts=0; parts < partitions; parts++) {
    List<Segment> segmentList=new ArrayList<Segment>(numSpills);
    for (int i=0; i < numSpills; i++) {
      Path spillFilename=mapOutputFile.getSpillFile(i);
      TezIndexRecord indexRecord=indexCacheList.get(i).getIndex(parts);
      Segment s=new Segment(conf,rfs,spillFilename,indexRecord.getStartOffset(),indexRecord.getPartLength(),codec,ifileReadAhead,ifileReadAheadLength,ifileBufferSize,true);
      segmentList.add(i,s);
    }
    int mergeFactor=this.conf.getInt(TezJobConfig.TEZ_RUNTIME_IO_SORT_FACTOR,TezJobConfig.DEFAULT_TEZ_RUNTIME_IO_SORT_FACTOR);
    boolean sortSegments=segmentList.size() > mergeFactor;
    TezRawKeyValueIterator kvIter=TezMerger.merge(conf,rfs,keyClass,valClass,codec,segmentList,mergeFactor,new Path(uniqueIdentifier),(RawComparator)ConfigUtils.getIntermediateOutputKeyComparator(conf),nullProgressable,sortSegments,true,null,spilledRecordsCounter,null,null);
    long segmentStart=finalOut.getPos();
    Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,spilledRecordsCounter,null);
    writer.setRLE(merger.needsRLE());
    if (combiner == null || numSpills < minSpillsForCombine) {
      TezMerger.writeFile(kvIter,writer,nullProgressable,TezJobConfig.DEFAULT_RECORDS_BEFORE_PROGRESS);
    }
 else {
      runCombineProcessor(kvIter,writer);
    }
    writer.close();
    final TezIndexRecord rec=new TezIndexRecord(segmentStart,writer.getRawLength(),writer.getCompressedLength());
    spillRec.putIndex(rec,parts);
  }
  spillRec.writeToFile(finalIndexFile,conf);
  finalOut.close();
  for (int i=0; i < numSpills; i++) {
    Path indexFilename=mapOutputFile.getSpillIndexFile(i);
    Path spillFilename=mapOutputFile.getSpillFile(i);
    rfs.delete(indexFilename,true);
    rfs.delete(spillFilename,true);
  }
}