Program: 4480
Project: 4480
Buggy source:
/** 
 * Tries one round of downloading of the given files.  Downloads from all locations until all locations fail or some locations succeed.  Moves incomplete file to the library on success.
 * @return COMPLETE if a file was successfully downloaded.  This canhappen even if the file is corrupt, if the user explicitly approved. CORRUPT_FILE a bytes mismatched when checking overlapping regions of resume or swarm, and the user decided they' did not want the download fragment, which is now quarantined. COULDNT_MOVE_TO_LIBRARY the download completed but the temporary file couldn't be moved to the library OR the download couldn't be written to the incomplete file WAITING_FOR_RETRY if no file was downloaded, but it makes sense  to try again later because some hosts reported busy. The caller should usually wait before retrying. GAVE_UP the download attempt failed, and there are  no more locations to try.
 * @exception InterruptedException if the user stop()'ed this download. (Calls to resume() do not result in InterruptedException.)
 */
private int tryAllDownloads2() throws InterruptedException {
synchronized (this) {
    if (files.size() == 0)     return GAVE_UP;
  }
  incompleteFile=incompleteFileManager.getFile((RemoteFileDesc)files.get(0));
  File saveDir;
  String fileName=getFileName();
  try {
    saveDir=SharingSettings.getSaveDirectory();
    completeFile=new File(saveDir,fileName);
    String savePath=saveDir.getCanonicalPath();
    String completeFileParentPath=new File(completeFile.getParent()).getCanonicalPath();
    if (!savePath.equals(completeFileParentPath))     throw new InvalidPathException();
  }
 catch (  IOException e) {
    return COULDNT_MOVE_TO_LIBRARY;
  }
  URN sha1=buckets.getURNForBucket(bucketNumber);
  if (sha1 != null)   validAlts=AlternateLocationCollection.create(sha1);
  int status=-1;
  try {
    status=tryAllDownloads3();
  }
 catch (  InterruptedException e) {
  }
  commonOutFile.close();
  if (corruptState != NOT_CORRUPT_STATE) {
synchronized (corruptStateLock) {
      try {
        while (corruptState == CORRUPT_WAITING_STATE) {
          corruptStateLock.wait();
        }
      }
 catch (      InterruptedException ignored) {
      }
    }
    if (corruptState == CORRUPT_STOP_STATE) {
      cleanupCorrupt(incompleteFile,completeFile.getName());
      return CORRUPT_FILE;
    }
 else     if (corruptState == CORRUPT_CONTINUE_STATE) {
      ;
    }
  }
  if (status == -1)   throw new InterruptedException();
  if (status != COMPLETE)   return status;
  URN bucketHash=buckets.getURNForBucket(bucketNumber);
  URN fileHash=null;
  try {
    setState(HASHING);
    fileHash=URN.createSHA1Urn(incompleteFile);
  }
 catch (  IOException ignored) {
  }
  if (bucketHash != null) {
synchronized (corruptStateLock) {
      if (!bucketHash.equals(fileHash)) {
        setState(CORRUPT_FILE);
        promptAboutCorruptDownload();
        if (LOG.isWarnEnabled())         LOG.warn("String_Node_Str" + fileHash + "String_Node_Str"+ bucketHash);
      }
      try {
        while (corruptState == CORRUPT_WAITING_STATE)         corruptStateLock.wait();
      }
 catch (      InterruptedException ignored2) {
      }
    }
    if (corruptState == CORRUPT_STOP_STATE) {
      cleanupCorrupt(incompleteFile,completeFile.getName());
      return CORRUPT_FILE;
    }
  }
  setState(SAVING);
  File completeFileDir=FileUtils.getParentFile(completeFile);
  FileUtils.setWriteable(completeFileDir);
  FileUtils.setWriteable(completeFile);
  completeFile.delete();
  boolean success=incompleteFile.renameTo(completeFile);
  if (!success) {
    FileDesc fd=RouterService.getFileManager().getFileDescForFile(incompleteFile);
    if (fd != null) {
      UploadManager upMan=RouterService.getUploadManager();
synchronized (upMan) {
        if (upMan.killUploadsForFileDesc(fd))         success=incompleteFile.renameTo(completeFile);
      }
    }
  }
  if (!success)   success=CommonUtils.copy(incompleteFile,completeFile);
  if (!success)   return COULDNT_MOVE_TO_LIBRARY;
  incompleteFileManager.removeEntry(incompleteFile);
  if (fileExists(completeFile))   fileManager.removeFileIfShared(completeFile);
  if (fileHash != null) {
    Set urns=new HashSet(1);
    urns.add(fileHash);
    File file=completeFile;
    try {
      file=FileUtils.getCanonicalFile(completeFile);
    }
 catch (    IOException ignored) {
    }
    if (fileManager.isFileInSharedDirectories(file))     UrnCache.instance().addUrns(file,urns);
  }
  FileDesc fileDesc=fileManager.addFileIfShared(completeFile,getXMLDocuments());
  if (validAlts != null && fileDesc != null && fileDesc.getSHA1Urn().equals(validAlts.getSHA1Urn())) {
    LOG.trace("String_Node_Str");
    addLocationsToFile(validAlts,fileDesc);
    callback.handleSharedFileUpdate(completeFile);
    HashSet set=null;
synchronized (this) {
      set=new HashSet(files);
    }
    if (fileDesc.getSize() < HTTPDownloader.MIN_PARTIAL_FILE_BYTES || !UploadSettings.ALLOW_PARTIAL_SHARING.getValue()) {
      LOG.trace("String_Node_Str");
      HeadRequester requester=new HeadRequester(set,fileHash,fileDesc,fileDesc.getAlternateLocationCollection());
      Thread headThread=new Thread(requester,"String_Node_Str");
      headThread.setDaemon(true);
      headThread.start();
    }
  }
  return COMPLETE;
}

Fixed version (ground truth):
/** 
 * Tries one round of downloading of the given files.  Downloads from all locations until all locations fail or some locations succeed.  Moves incomplete file to the library on success.
 * @return COMPLETE if a file was successfully downloaded.  This canhappen even if the file is corrupt, if the user explicitly approved. CORRUPT_FILE a bytes mismatched when checking overlapping regions of resume or swarm, and the user decided they' did not want the download fragment, which is now quarantined. COULDNT_MOVE_TO_LIBRARY the download completed but the temporary file couldn't be moved to the library OR the download couldn't be written to the incomplete file WAITING_FOR_RETRY if no file was downloaded, but it makes sense  to try again later because some hosts reported busy. The caller should usually wait before retrying. GAVE_UP the download attempt failed, and there are  no more locations to try.
 * @exception InterruptedException if the user stop()'ed this download. (Calls to resume() do not result in InterruptedException.)
 */
private int tryAllDownloads2() throws InterruptedException {
synchronized (this) {
    if (files.size() == 0)     return GAVE_UP;
  }
  File saveDir;
  String fileName=getFileName();
  try {
    incompleteFile=incompleteFileManager.getFile((RemoteFileDesc)files.get(0));
    saveDir=SharingSettings.getSaveDirectory();
    completeFile=new File(saveDir,fileName);
    String savePath=saveDir.getCanonicalPath();
    String completeFileParentPath=new File(completeFile.getParent()).getCanonicalPath();
    if (!savePath.equals(completeFileParentPath))     return COULDNT_MOVE_TO_LIBRARY;
  }
 catch (  IOException e) {
    ErrorService.error(e,"String_Node_Str" + incompleteFile);
    return COULDNT_MOVE_TO_LIBRARY;
  }
  URN sha1=buckets.getURNForBucket(bucketNumber);
  if (sha1 != null)   validAlts=AlternateLocationCollection.create(sha1);
  int status=-1;
  try {
    status=tryAllDownloads3();
  }
 catch (  InterruptedException e) {
  }
  commonOutFile.close();
  if (corruptState != NOT_CORRUPT_STATE) {
synchronized (corruptStateLock) {
      try {
        while (corruptState == CORRUPT_WAITING_STATE) {
          corruptStateLock.wait();
        }
      }
 catch (      InterruptedException ignored) {
      }
    }
    if (corruptState == CORRUPT_STOP_STATE) {
      cleanupCorrupt(incompleteFile,completeFile.getName());
      return CORRUPT_FILE;
    }
 else     if (corruptState == CORRUPT_CONTINUE_STATE) {
      ;
    }
  }
  if (status == -1)   throw new InterruptedException();
  if (status != COMPLETE)   return status;
  URN bucketHash=buckets.getURNForBucket(bucketNumber);
  URN fileHash=null;
  try {
    setState(HASHING);
    fileHash=URN.createSHA1Urn(incompleteFile);
  }
 catch (  IOException ignored) {
  }
  if (bucketHash != null) {
synchronized (corruptStateLock) {
      if (!bucketHash.equals(fileHash)) {
        setState(CORRUPT_FILE);
        promptAboutCorruptDownload();
        if (LOG.isWarnEnabled())         LOG.warn("String_Node_Str" + fileHash + "String_Node_Str"+ bucketHash);
      }
      try {
        while (corruptState == CORRUPT_WAITING_STATE)         corruptStateLock.wait();
      }
 catch (      InterruptedException ignored2) {
      }
    }
    if (corruptState == CORRUPT_STOP_STATE) {
      cleanupCorrupt(incompleteFile,completeFile.getName());
      return CORRUPT_FILE;
    }
  }
  setState(SAVING);
  File completeFileDir=FileUtils.getParentFile(completeFile);
  FileUtils.setWriteable(completeFileDir);
  FileUtils.setWriteable(completeFile);
  completeFile.delete();
  boolean success=incompleteFile.renameTo(completeFile);
  if (!success) {
    FileDesc fd=RouterService.getFileManager().getFileDescForFile(incompleteFile);
    if (fd != null) {
      UploadManager upMan=RouterService.getUploadManager();
synchronized (upMan) {
        if (upMan.killUploadsForFileDesc(fd))         success=incompleteFile.renameTo(completeFile);
      }
    }
  }
  if (!success)   success=CommonUtils.copy(incompleteFile,completeFile);
  if (!success)   return COULDNT_MOVE_TO_LIBRARY;
  incompleteFileManager.removeEntry(incompleteFile);
  if (fileExists(completeFile))   fileManager.removeFileIfShared(completeFile);
  if (fileHash != null) {
    Set urns=new HashSet(1);
    urns.add(fileHash);
    File file=completeFile;
    try {
      file=FileUtils.getCanonicalFile(completeFile);
    }
 catch (    IOException ignored) {
    }
    if (fileManager.isFileInSharedDirectories(file))     UrnCache.instance().addUrns(file,urns);
  }
  FileDesc fileDesc=fileManager.addFileIfShared(completeFile,getXMLDocuments());
  if (validAlts != null && fileDesc != null && fileDesc.getSHA1Urn().equals(validAlts.getSHA1Urn())) {
    LOG.trace("String_Node_Str");
    addLocationsToFile(validAlts,fileDesc);
    callback.handleSharedFileUpdate(completeFile);
    HashSet set=null;
synchronized (this) {
      set=new HashSet(files);
    }
    if (fileDesc.getSize() < HTTPDownloader.MIN_PARTIAL_FILE_BYTES || !UploadSettings.ALLOW_PARTIAL_SHARING.getValue()) {
      LOG.trace("String_Node_Str");
      HeadRequester requester=new HeadRequester(set,fileHash,fileDesc,fileDesc.getAlternateLocationCollection());
      Thread headThread=new Thread(requester,"String_Node_Str");
      headThread.setDaemon(true);
      headThread.start();
    }
  }
  return COMPLETE;
}