Program: 17254
Project: 17254
Buggy source:
private void mergeParts() throws IOException {
  long finalOutFileSize=0;
  long finalIndexFileSize=0;
  final Path[] filename=new Path[numSpills];
  final String taskIdentifier=outputContext.getUniqueIdentifier();
  for (int i=0; i < numSpills; i++) {
    filename[i]=mapOutputFile.getSpillFile(i);
    finalOutFileSize+=rfs.getFileStatus(filename[i]).getLen();
  }
  if (numSpills == 1) {
    sameVolRename(filename[0],mapOutputFile.getOutputFileForWriteInVolume(filename[0]));
    if (indexCacheList.size() == 0) {
      sameVolRename(mapOutputFile.getSpillIndexFile(0),mapOutputFile.getOutputIndexFileForWriteInVolume(filename[0]));
    }
 else {
      indexCacheList.get(0).writeToFile(mapOutputFile.getOutputIndexFileForWriteInVolume(filename[0]),conf);
    }
    return;
  }
  for (int i=indexCacheList.size(); i < numSpills; ++i) {
    Path indexFileName=mapOutputFile.getSpillIndexFile(i);
    indexCacheList.add(new TezSpillRecord(indexFileName,conf));
  }
  finalOutFileSize+=partitions * APPROX_HEADER_LENGTH;
  finalIndexFileSize=partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;
  Path finalOutputFile=mapOutputFile.getOutputFileForWrite(finalOutFileSize);
  Path finalIndexFile=mapOutputFile.getOutputIndexFileForWrite(finalIndexFileSize);
  FSDataOutputStream finalOut=rfs.create(finalOutputFile,true,4096);
  if (numSpills == 0) {
    TezSpillRecord sr=new TezSpillRecord(partitions);
    try {
      for (int i=0; i < partitions; i++) {
        long segmentStart=finalOut.getPos();
        Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,null,null);
        writer.close();
        TezIndexRecord rec=new TezIndexRecord(segmentStart,writer.getRawLength(),writer.getCompressedLength());
        outputBytesWithOverheadCounter.increment(writer.getRawLength());
        sr.putIndex(rec,i);
      }
      sr.writeToFile(finalIndexFile,conf);
    }
  finally {
      finalOut.close();
    }
    return;
  }
 else {
    TezMerger.considerFinalMergeForProgress();
    final TezSpillRecord spillRec=new TezSpillRecord(partitions);
    for (int parts=0; parts < partitions; parts++) {
      List<Segment> segmentList=new ArrayList<Segment>(numSpills);
      for (int i=0; i < numSpills; i++) {
        TezIndexRecord indexRecord=indexCacheList.get(i).getIndex(parts);
        Segment s=new Segment(conf,rfs,filename[i],indexRecord.getStartOffset(),indexRecord.getPartLength(),codec,ifileReadAhead,ifileReadAheadLength,ifileBufferSize,true);
        segmentList.add(i,s);
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + taskIdentifier + "String_Node_Str"+ parts+ "String_Node_Str"+ i+ "String_Node_Str"+ indexRecord.getStartOffset()+ "String_Node_Str"+ indexRecord.getRawLength()+ "String_Node_Str"+ indexRecord.getPartLength()+ "String_Node_Str");
        }
      }
      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(taskIdentifier),(RawComparator)ConfigUtils.getIntermediateOutputKeyComparator(conf),nullProgressable,sortSegments,null,spilledRecordsCounter,additionalSpillBytesRead,null);
      long segmentStart=finalOut.getPos();
      Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,spilledRecordsCounter,null);
      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++) {
      rfs.delete(filename[i],true);
    }
  }
}

Fixed version (ground truth):
private void mergeParts() throws IOException {
  long finalOutFileSize=0;
  long finalIndexFileSize=0;
  final Path[] filename=new Path[numSpills];
  final String taskIdentifier=outputContext.getUniqueIdentifier();
  for (int i=0; i < numSpills; i++) {
    filename[i]=mapOutputFile.getSpillFile(i);
    finalOutFileSize+=rfs.getFileStatus(filename[i]).getLen();
  }
  if (numSpills == 1) {
    sameVolRename(filename[0],mapOutputFile.getOutputFileForWriteInVolume(filename[0]));
    if (indexCacheList.size() == 0) {
      sameVolRename(mapOutputFile.getSpillIndexFile(0),mapOutputFile.getOutputIndexFileForWriteInVolume(filename[0]));
    }
 else {
      indexCacheList.get(0).writeToFile(mapOutputFile.getOutputIndexFileForWriteInVolume(filename[0]),conf);
    }
    return;
  }
  for (int i=indexCacheList.size(); i < numSpills; ++i) {
    Path indexFileName=mapOutputFile.getSpillIndexFile(i);
    indexCacheList.add(new TezSpillRecord(indexFileName,conf));
  }
  finalOutFileSize+=partitions * APPROX_HEADER_LENGTH;
  finalIndexFileSize=partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;
  Path finalOutputFile=mapOutputFile.getOutputFileForWrite(finalOutFileSize);
  Path finalIndexFile=mapOutputFile.getOutputIndexFileForWrite(finalIndexFileSize);
  FSDataOutputStream finalOut=rfs.create(finalOutputFile,true,4096);
  if (numSpills == 0) {
    TezSpillRecord sr=new TezSpillRecord(partitions);
    try {
      for (int i=0; i < partitions; i++) {
        long segmentStart=finalOut.getPos();
        Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,null,null);
        writer.close();
        TezIndexRecord rec=new TezIndexRecord(segmentStart,writer.getRawLength(),writer.getCompressedLength());
        outputBytesWithOverheadCounter.increment(writer.getRawLength());
        sr.putIndex(rec,i);
      }
      sr.writeToFile(finalIndexFile,conf);
    }
  finally {
      finalOut.close();
    }
    return;
  }
 else {
    final TezSpillRecord spillRec=new TezSpillRecord(partitions);
    for (int parts=0; parts < partitions; parts++) {
      List<Segment> segmentList=new ArrayList<Segment>(numSpills);
      for (int i=0; i < numSpills; i++) {
        TezIndexRecord indexRecord=indexCacheList.get(i).getIndex(parts);
        Segment s=new Segment(conf,rfs,filename[i],indexRecord.getStartOffset(),indexRecord.getPartLength(),codec,ifileReadAhead,ifileReadAheadLength,ifileBufferSize,true);
        segmentList.add(i,s);
        if (LOG.isDebugEnabled()) {
          LOG.debug("String_Node_Str" + taskIdentifier + "String_Node_Str"+ parts+ "String_Node_Str"+ i+ "String_Node_Str"+ indexRecord.getStartOffset()+ "String_Node_Str"+ indexRecord.getRawLength()+ "String_Node_Str"+ indexRecord.getPartLength()+ "String_Node_Str");
        }
      }
      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(taskIdentifier),(RawComparator)ConfigUtils.getIntermediateOutputKeyComparator(conf),nullProgressable,sortSegments,true,null,spilledRecordsCounter,additionalSpillBytesRead,null);
      long segmentStart=finalOut.getPos();
      Writer writer=new Writer(conf,finalOut,keyClass,valClass,codec,spilledRecordsCounter,null);
      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++) {
      rfs.delete(filename[i],true);
    }
  }
}