Program: 4984
Project: 4984
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.
 * @param files a list of files to pick from, all of which MUST be"identical" instances of RemoteFileDesc.  Unreachable locations are removed from files.
 * @return COMPLETE if a file was successfully downloadedCOULDNT_MOVE_TO_LIBRARY the download completed but the temporary file couldn't be moved to the library 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(final List files) throws InterruptedException {
  if (files.size() == 0)   return GAVE_UP;
  RemoteFileDesc rfd=(RemoteFileDesc)files.get(0);
  int fileSize=rfd.getSize();
  String filename=rfd.getFileName();
  File incompleteFile=incompleteFileManager.getFile(rfd);
  File sharedDir;
  File completeFile;
  try {
    sharedDir=SettingsManager.instance().getSaveDirectory();
    completeFile=new File(sharedDir,filename);
    String sharedPath=sharedDir.getCanonicalPath();
    String completeFileParentPath=new File(completeFile.getParent()).getCanonicalPath();
    if (!sharedPath.equals(completeFileParentPath))     throw new InvalidPathException();
  }
 catch (  IOException e) {
    return COULDNT_MOVE_TO_LIBRARY;
  }
  int status=tryAllDownloads3(files);
  if (status != COMPLETE)   return status;
  completeFile.delete();
  if (!incompleteFile.renameTo(completeFile))   if (!CommonUtils.copy(incompleteFile,completeFile))   return COULDNT_MOVE_TO_LIBRARY;
  fileManager.addFileIfShared(completeFile,getXMLDocuments());
  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.
 * @param files a list of files to pick from, all of which MUST be"identical" instances of RemoteFileDesc.  Unreachable locations are removed from files.
 * @return COMPLETE if a file was successfully downloadedCOULDNT_MOVE_TO_LIBRARY the download completed but the temporary file couldn't be moved to the library 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(final List files) throws InterruptedException {
  if (files.size() == 0)   return GAVE_UP;
  RemoteFileDesc rfd=(RemoteFileDesc)files.get(0);
  int fileSize=rfd.getSize();
  String filename=rfd.getFileName();
  File incompleteFile=incompleteFileManager.getFile(rfd);
  File sharedDir;
  File completeFile;
  try {
    sharedDir=SettingsManager.instance().getSaveDirectory();
    completeFile=new File(sharedDir,filename);
    String sharedPath=sharedDir.getCanonicalPath();
    String completeFileParentPath=new File(completeFile.getParent()).getCanonicalPath();
    if (!sharedPath.equals(completeFileParentPath))     throw new InvalidPathException();
  }
 catch (  IOException e) {
    return COULDNT_MOVE_TO_LIBRARY;
  }
  int status=tryAllDownloads3(files);
  if (status != COMPLETE)   return status;
  completeFile.delete();
  if (!incompleteFile.renameTo(completeFile))   if (!CommonUtils.copy(incompleteFile,completeFile))   return COULDNT_MOVE_TO_LIBRARY;
  if (fileExists(completeFile))   fileManager.removeFileIfShared(completeFile);
  fileManager.addFileIfShared(completeFile,getXMLDocuments());
  return COMPLETE;
}