Program: 4808
Project: 4808
Buggy source:
/** 
 * Returns the fully-qualified temporary download file for the given file/location pair.  The location of the file is determined by the INCOMPLETE_DIRECTORY property.  For example, getFile("test.txt", 1999) may return "C:\Program Files\LimeWire\Incomplete\T-1999-Test.txt".  The disk is not modified.<p> This method gives duplicate files the same temporary file, which is critical for resume and swarmed downloads.  That is, for all rfd_i and  rfd_j <pre> rfd_i~=rfd_j <==> getFile(rfd_i).equals(getFile(rfd_j))<p>   </pre> Where "~=" means "has the same content as".  Currently rfd_i~=rfd_j iff either of the following conditions hold:  <ul> <li>Both files have the same hash, i.e.,  rfd_i.getSHA1Urn().equals(rfd_j.getSHA1Urn().  Note that this (almost) always means that rfd_i.getSize()==rfd_j.getSize(), though rfd_i and rfd_j may have different names. <li>Both files have the same name and size and don't have conflicting hashes, i.e., rfd_i.getName().equals(rfd_j.getName()) && rfd_i.getSize()==rfd_j.getSize() && (rfd_i.getSHA1Urn()==null || rfd_j.getSHA1Urn()==null ||  rfd_i.getSHA1Urn().equals(rfd_j.getSHA1Urn())). </ul> Note that the second condition allows risky resumes, i.e., resumes when  one (or both) of the files doesn't have a hash.
 */
public synchronized File getFile(RemoteFileDesc rfd){
  File incDir=null;
  try {
    incDir=SettingsManager.instance().getIncompleteDirectory();
  }
 catch (  java.io.FileNotFoundException fnfe) {
  }
  URN sha1=rfd.getSHA1Urn();
  if (sha1 != null) {
    File file=(File)hashes.get(sha1);
    if (file != null) {
      return file;
    }
 else {
      for (int i=1; ; i++) {
        file=new File(incDir,tempName(rfd.getFileName(),rfd.getSize(),i));
        if (!hashes.values().contains(file))         break;
      }
      hashes.put(sha1,file);
      return file;
    }
  }
 else {
    return new File(incDir,tempName(rfd.getFileName(),rfd.getSize(),0));
  }
}

Fixed version (ground truth):
/** 
 * Returns the fully-qualified temporary download file for the given file/location pair.  The location of the file is determined by the INCOMPLETE_DIRECTORY property.  For example, getFile("test.txt", 1999) may return "C:\Program Files\LimeWire\Incomplete\T-1999-Test.txt".  The disk is not modified.<p> This method gives duplicate files the same temporary file, which is critical for resume and swarmed downloads.  That is, for all rfd_i and  rfd_j <pre> similar(rfd_i, rfd_j) <==> getFile(rfd_i).equals(getFile(rfd_j))<p>   </pre>
 */
public synchronized File getFile(RemoteFileDesc rfd){
  File incDir=null;
  try {
    incDir=SettingsManager.instance().getIncompleteDirectory();
  }
 catch (  java.io.FileNotFoundException fnfe) {
  }
  URN sha1=rfd.getSHA1Urn();
  if (sha1 != null) {
    File file=(File)hashes.get(sha1);
    if (file != null) {
      return file;
    }
 else {
      for (int i=1; ; i++) {
        file=new File(incDir,tempName(rfd.getFileName(),rfd.getSize(),i));
        if (!hashes.values().contains(file))         break;
      }
      hashes.put(sha1,file);
      return file;
    }
  }
 else {
    return new File(incDir,tempName(rfd.getFileName(),rfd.getSize(),0));
  }
}