Program: 5047
Project: 5047
Buggy source:
/** 
 * Tries to "smart download" any of the given files.<p>   If overwrite==false, then if any of the files already exists in the download directory, FileExistsException is thrown and no files are modified.  If overwrite==true, the files may be overwritten.<p> Otherwise returns a Downloader that allows you to stop and resume this download.  The ActivityCallback will also be notified of this download, so the return value can usually be ignored.  The download begins immediately, unless it is queued.  It stops after any of the files succeeds.
 * @modifies this, disk 
 */
public synchronized Downloader getFiles(RemoteFileDesc[] files,boolean overwrite) throws FileExistsException {
  if (!overwrite) {
    String downloadDir=SettingsManager.instance().getSaveDirectory();
    for (int i=0; i < files.length; i++) {
      String filename=files[i].getFileName();
      File completeFile=new File(downloadDir,filename);
      if (completeFile.exists())       throw new FileExistsException(filename);
    }
  }
  ManagedDownloader downloader=new ManagedDownloader(this,files);
  waiting.add(downloader);
  callback.addDownload(downloader);
  return downloader;
}

Fixed version (ground truth):
/** 
 * Tries to "smart download" any of the given files.<p>   If any of the files already being downloaded (or queued for downloaded) has the same temporary name as any of the files in 'files', throws AlreadyDownloadingException.  Note, however, that this doesn't guarantee that a successfully downloaded file can be moved to the library.<p> If overwrite==false, then if any of the files already exists in the download directory, FileExistsException is thrown and no files are modified.  If overwrite==true, the files may be overwritten.<p> Otherwise returns a Downloader that allows you to stop and resume this download.  The ActivityCallback will also be notified of this download, so the return value can usually be ignored.  The download begins immediately, unless it is queued.  It stops after any of the files succeeds.
 * @modifies this, disk 
 */
public synchronized Downloader getFiles(RemoteFileDesc[] files,boolean overwrite) throws FileExistsException, AlreadyDownloadingException {
  for (int i=0; i < files.length; i++) {
    for (Iterator iter=active.iterator(); iter.hasNext(); ) {
      ManagedDownloader md=(ManagedDownloader)iter.next();
      if (md.conflicts(files[i]))       throw new AlreadyDownloadingException(files[i].getFileName());
    }
    for (Iterator iter=waiting.iterator(); iter.hasNext(); ) {
      ManagedDownloader md=(ManagedDownloader)iter.next();
      if (md.conflicts(files[i]))       throw new AlreadyDownloadingException(files[i].getFileName());
    }
  }
  if (!overwrite) {
    String downloadDir=SettingsManager.instance().getSaveDirectory();
    for (int i=0; i < files.length; i++) {
      String filename=files[i].getFileName();
      File completeFile=new File(downloadDir,filename);
      if (completeFile.exists())       throw new FileExistsException(filename);
    }
  }
  ManagedDownloader downloader=new ManagedDownloader(this,files);
  waiting.add(downloader);
  callback.addDownload(downloader);
  return downloader;
}