Program: 76845
Project: 76845
Buggy source:
static void archive(String folderName,IStreamSorter streamSorter,RandomAccessFile compoundFile) throws IOException {
  compoundFile.setLength(0);
  compoundFile.seek(0);
  compoundFile.writeLong(0);
  compoundFile.writeLong(0);
  ArrayList fileList=new ArrayList();
  getAllFiles(new File(folderName),fileList);
  if (streamSorter != null) {
    ArrayList streamNameList=new ArrayList();
    for (int i=0; i < fileList.size(); i++) {
      File file=(File)fileList.get(i);
      streamNameList.add(ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath()));
    }
    ArrayList sortedNameList=streamSorter.sortStream(streamNameList);
    if (sortedNameList != null) {
      fileList.clear();
      for (int i=0; i < sortedNameList.size(); i++) {
        String fileName=ArchiveUtil.generateFullPath(folderName,(String)sortedNameList.get(i));
        fileList.add(new File(fileName));
      }
    }
  }
  long streamRelativePosition=0;
  long entryNum=0;
  for (int i=0; i < fileList.size(); i++) {
    File file=(File)fileList.get(i);
    String relativePath=ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath());
    if (!needSkip(relativePath)) {
      compoundFile.writeUTF(relativePath);
      compoundFile.writeLong(streamRelativePosition);
      compoundFile.writeLong(file.length());
      streamRelativePosition+=file.length();
      entryNum++;
    }
  }
  long streamSectionPos=compoundFile.getFilePointer();
  for (int i=0; i < fileList.size(); i++) {
    File file=(File)fileList.get(i);
    String relativePath=ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath());
    if (!needSkip(relativePath)) {
      copyFileIntoTheArchive(file,compoundFile);
    }
  }
  compoundFile.seek(0);
  compoundFile.writeLong(streamSectionPos);
  compoundFile.writeLong(entryNum);
}

Fixed version (ground truth):
static void archive(String folderName,IStreamSorter streamSorter,RandomAccessFile compoundFile) throws IOException {
  compoundFile.setLength(0);
  compoundFile.seek(0);
  compoundFile.writeLong(0);
  compoundFile.writeLong(0);
  ArrayList fileList=new ArrayList();
  folderName=new File(folderName).getCanonicalPath();
  getAllFiles(new File(folderName),fileList);
  if (streamSorter != null) {
    ArrayList streamNameList=new ArrayList();
    for (int i=0; i < fileList.size(); i++) {
      File file=(File)fileList.get(i);
      streamNameList.add(ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath()));
    }
    ArrayList sortedNameList=streamSorter.sortStream(streamNameList);
    if (sortedNameList != null) {
      fileList.clear();
      for (int i=0; i < sortedNameList.size(); i++) {
        String fileName=ArchiveUtil.generateFullPath(folderName,(String)sortedNameList.get(i));
        fileList.add(new File(fileName));
      }
    }
  }
  long streamRelativePosition=0;
  long entryNum=0;
  for (int i=0; i < fileList.size(); i++) {
    File file=(File)fileList.get(i);
    String relativePath=ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath());
    if (!needSkip(relativePath)) {
      compoundFile.writeUTF(relativePath);
      compoundFile.writeLong(streamRelativePosition);
      compoundFile.writeLong(file.length());
      streamRelativePosition+=file.length();
      entryNum++;
    }
  }
  long streamSectionPos=compoundFile.getFilePointer();
  for (int i=0; i < fileList.size(); i++) {
    File file=(File)fileList.get(i);
    String relativePath=ArchiveUtil.generateRelativePath(folderName,file.getAbsolutePath());
    if (!needSkip(relativePath)) {
      copyFileIntoTheArchive(file,compoundFile);
    }
  }
  compoundFile.seek(0);
  compoundFile.writeLong(streamSectionPos);
  compoundFile.writeLong(entryNum);
}