Program: 89588
Project: 89588
Buggy source:
/** 
 * Documents the harvest under the given dir in a packaged metadata arc file in a directory 'metadata' under the current dir. Only documents the files belonging to the given jobID, the rest are moved to oldjobs. In the current implementation, the documentation consists of CDX indices over all ARC files (with one CDX record per harvested ARC file), plus packaging of log files. If this method finishes without an exception, it is guaranteed that metadata is ready for upload. TODO Place preharvestmetadata in IngestableFiles-defined area TODO This method may be a good place to copy deduplicate information from the crawl log to the cdx file.
 * @param crawlDir The directory the crawl was performed in
 * @param jobID the ID of the job for this harvest
 * @param harvestID the ID of the harvestdefinition which created this job.
 * @throws ArgumentNotValid if crawlDir is null or does not exist, or ifjobID or harvestID is negative.
 * @throws IOFailure if- reading ARC files or temporary files fails - writing a file to arcFilesDir fails
 */
public static void documentHarvest(File crawlDir,long jobID,long harvestID) throws IOFailure {
  ArgumentNotValid.checkNotNull(crawlDir,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(jobID,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(harvestID,"String_Node_Str");
  ArgumentNotValid.checkExistsDirectory(crawlDir,"String_Node_Str");
  IngestableFiles ingestables=new IngestableFiles(crawlDir,jobID);
  if (ingestables.isMetadataReady()) {
    log.warn("String_Node_Str" + ingestables.getMetadataFile().getAbsolutePath() + "String_Node_Str");
    return;
  }
  List<File> filesAddedAndNowDeletable=null;
  try {
    MetadataFileWriter mdfw=null;
    mdfw=ingestables.getMetadataWriter();
    if (mdfw instanceof MetadataFileWriterWarc) {
      ANVLRecord infoPayload=new ANVLRecord(3);
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str" + dk.netarkivet.common.Constants.getVersionString() + "String_Node_Str"+ dk.netarkivet.common.Constants.PROJECT_WEBSITE);
      infoPayload.addLabelValue("String_Node_Str",SystemUtils.getLocalIP());
      infoPayload.addLabelValue("String_Node_Str",SystemUtils.getLocalHostName());
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str");
      PersistentJobData psj=new PersistentJobData(crawlDir);
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str" + psj.getJobID());
      MetadataFileWriterWarc mfww=(MetadataFileWriterWarc)mdfw;
      mfww.insertInfoRecord(infoPayload);
    }
    List<MetadataEntry> storedMetadata=getStoredMetadata(crawlDir);
    try {
      for (      MetadataEntry m : storedMetadata) {
        mdfw.write(m.getURL(),m.getMimeType(),SystemUtils.getLocalIP(),System.currentTimeMillis(),m.getData());
      }
    }
 catch (    IOException e) {
      log.warn("String_Node_Str",e);
    }
    filesAddedAndNowDeletable=writeHarvestDetails(jobID,harvestID,crawlDir,mdfw,Constants.getHeritrixVersionString());
    Iterator<File> iterator=filesAddedAndNowDeletable.iterator();
    while (iterator.hasNext()) {
      File f=iterator.next();
      if (f.getName().equals("String_Node_Str") || f.getName().equals("String_Node_Str") || f.getName().equals("String_Node_Str")) {
        iterator.remove();
      }
    }
    boolean cdxGenerationSucceeded=false;
    File arcFilesDir=ingestables.getArcsDir();
    File warcFilesDir=ingestables.getWarcsDir();
    if (arcFilesDir.exists()) {
      addCDXes(ingestables,arcFilesDir,mdfw,ArchiveProfile.ARC_PROFILE);
      cdxGenerationSucceeded=true;
    }
    if (warcFilesDir.exists()) {
      addCDXes(ingestables,arcFilesDir,mdfw,ArchiveProfile.WARC_PROFILE);
      cdxGenerationSucceeded=true;
    }
    if (cdxGenerationSucceeded) {
      ingestables.setMetadataGenerationSucceeded(true);
    }
 else {
      log.warn("String_Node_Str" + arcFilesDir.getAbsolutePath() + "String_Node_Str"+ warcFilesDir.getAbsolutePath()+ "String_Node_Str");
    }
  }
  finally {
    if (!ingestables.isMetadataReady()) {
      ingestables.setMetadataGenerationSucceeded(false);
    }
 else {
      for (      File fileAdded : filesAddedAndNowDeletable) {
        FileUtils.remove(fileAdded);
      }
      ingestables.cleanup();
    }
  }
}

Fixed version (ground truth):
/** 
 * Documents the harvest under the given dir in a packaged metadata arc file in a directory 'metadata' under the current dir. Only documents the files belonging to the given jobID, the rest are moved to oldjobs. In the current implementation, the documentation consists of CDX indices over all ARC files (with one CDX record per harvested ARC file), plus packaging of log files. If this method finishes without an exception, it is guaranteed that metadata is ready for upload. TODO Place preharvestmetadata in IngestableFiles-defined area TODO This method may be a good place to copy deduplicate information from the crawl log to the cdx file.
 * @param crawlDir The directory the crawl was performed in
 * @param jobID the ID of the job for this harvest
 * @param harvestID the ID of the harvestdefinition which created this job.
 * @throws ArgumentNotValid if crawlDir is null or does not exist, or ifjobID or harvestID is negative.
 * @throws IOFailure if- reading ARC files or temporary files fails - writing a file to arcFilesDir fails
 */
public static void documentHarvest(File crawlDir,long jobID,long harvestID) throws IOFailure {
  ArgumentNotValid.checkNotNull(crawlDir,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(jobID,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(harvestID,"String_Node_Str");
  ArgumentNotValid.checkExistsDirectory(crawlDir,"String_Node_Str");
  IngestableFiles ingestables=new IngestableFiles(crawlDir,jobID);
  if (ingestables.isMetadataReady()) {
    log.warn("String_Node_Str" + ingestables.getMetadataFile().getAbsolutePath() + "String_Node_Str");
    return;
  }
  List<File> filesAddedAndNowDeletable=null;
  try {
    MetadataFileWriter mdfw=null;
    mdfw=ingestables.getMetadataWriter();
    if (mdfw instanceof MetadataFileWriterWarc) {
      ANVLRecord infoPayload=new ANVLRecord(3);
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str" + dk.netarkivet.common.Constants.getVersionString() + "String_Node_Str"+ dk.netarkivet.common.Constants.PROJECT_WEBSITE);
      infoPayload.addLabelValue("String_Node_Str",SystemUtils.getLocalIP());
      infoPayload.addLabelValue("String_Node_Str",SystemUtils.getLocalHostName());
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str");
      PersistentJobData psj=new PersistentJobData(crawlDir);
      infoPayload.addLabelValue("String_Node_Str","String_Node_Str" + psj.getJobID());
      MetadataFileWriterWarc mfww=(MetadataFileWriterWarc)mdfw;
      mfww.insertInfoRecord(infoPayload);
    }
    List<MetadataEntry> storedMetadata=getStoredMetadata(crawlDir);
    try {
      for (      MetadataEntry m : storedMetadata) {
        mdfw.write(m.getURL(),m.getMimeType(),SystemUtils.getLocalIP(),System.currentTimeMillis(),m.getData());
      }
    }
 catch (    IOException e) {
      log.warn("String_Node_Str",e);
    }
    filesAddedAndNowDeletable=writeHarvestDetails(jobID,harvestID,crawlDir,mdfw,Constants.getHeritrixVersionString());
    Iterator<File> iterator=filesAddedAndNowDeletable.iterator();
    while (iterator.hasNext()) {
      File f=iterator.next();
      if (f.getName().equals("String_Node_Str") || f.getName().equals("String_Node_Str") || f.getName().equals("String_Node_Str")) {
        iterator.remove();
      }
    }
    boolean cdxGenerationSucceeded=false;
    File arcFilesDir=ingestables.getArcsDir();
    File warcFilesDir=ingestables.getWarcsDir();
    if (arcFilesDir.isDirectory() && FileUtils.hasFiles(arcFilesDir)) {
      addCDXes(ingestables,arcFilesDir,mdfw,ArchiveProfile.ARC_PROFILE);
      cdxGenerationSucceeded=true;
    }
    if (warcFilesDir.isDirectory() && FileUtils.hasFiles(warcFilesDir)) {
      addCDXes(ingestables,warcFilesDir,mdfw,ArchiveProfile.WARC_PROFILE);
      cdxGenerationSucceeded=true;
    }
    if (cdxGenerationSucceeded) {
      ingestables.setMetadataGenerationSucceeded(true);
    }
 else {
      log.warn("String_Node_Str" + arcFilesDir.getAbsolutePath() + "String_Node_Str"+ warcFilesDir.getAbsolutePath()+ "String_Node_Str");
    }
  }
  finally {
    if (!ingestables.isMetadataReady()) {
      ingestables.setMetadataGenerationSucceeded(false);
    }
 else {
      for (      File fileAdded : filesAddedAndNowDeletable) {
        FileUtils.remove(fileAdded);
      }
      ingestables.cleanup();
    }
  }
}