nus-yam/ex-repair huggingface dataset:
Program: 4789
Project: 4789
Buggy source:
public void testPerHostLimitedNotQueued(){
  UploadManager upManager=new UploadManager();
  SettingsManager.instance().setMaxUploads(2);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(2);
  SettingsManager.instance().setUploadQueueSize(2);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    connectDloader(d2,true,rfd1,true);
    HTTPDownloader d3=addUploader(upManager,rfd3,"String_Node_Str",true);
    try {
      connectDloader(d3,true,rfd1,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException expectedException) {
    }
catch (    IOException ioe) {
    }
    HTTPDownloader d4=addUploader(upManager,rfd4,"String_Node_Str",true);
    try {
      connectDloader(d4,true,rfd1,true);
      fail("String_Node_Str");
    }
 catch (    TryAgainLaterException tx) {
      fail("String_Node_Str");
    }
catch (    QueuedException expectedException) {
    }
catch (    IOException ioe) {
      fail("String_Node_Str");
    }
  }
 catch (  Exception anyOther) {
    System.out.println("String_Node_Str");
    anyOther.printStackTrace();
  }
  System.out.println("String_Node_Str");
}

Fixed version (ground truth):
public void testPerHostLimitedNotQueued(){
  UploadManager upManager=new UploadManager();
  setUploadManager(upManager);
  SettingsManager.instance().setMaxUploads(2);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(2);
  SettingsManager.instance().setUploadQueueSize(2);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    connectDloader(d2,true,rfd1,true);
    HTTPDownloader d3=addUploader(upManager,rfd3,"String_Node_Str",true);
    try {
      connectDloader(d3,true,rfd1,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException expectedException) {
    }
catch (    IOException ioe) {
    }
    HTTPDownloader d4=addUploader(upManager,rfd4,"String_Node_Str",true);
    try {
      connectDloader(d4,true,rfd1,true);
      fail("String_Node_Str");
    }
 catch (    TryAgainLaterException tx) {
      fail("String_Node_Str");
    }
catch (    QueuedException expectedException) {
    }
catch (    IOException ioe) {
      fail("String_Node_Str");
    }
  }
 catch (  Exception anyOther) {
    System.out.println("String_Node_Str");
    anyOther.printStackTrace();
  }
  System.out.println("String_Node_Str");
}
Program: 4790
Project: 4790
Buggy source:
/** 
 * We should count the number of uploads in progress AND the number of uploads the upload queue before deciding the upload per host limit. Tests this. 
 */
public void testUploadLimtIncludesQueue(){
  UploadManager upManager=new UploadManager();
  SettingsManager.instance().setMaxUploads(1);
  SettingsManager.instance().setSoftMaxUploads(1);
  SettingsManager.instance().setUploadsPerPerson(1);
  SettingsManager.instance().setUploadQueueSize(10);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    try {
      HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
      connectDloader(d2,true,rfd2,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception e) {
      fail("String_Node_Str");
    }
    try {
      HTTPDownloader d3=addUploader(upManager,rfd2,"String_Node_Str",true);
      connectDloader(d3,true,rfd2,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException talx) {
    }
catch (    Exception e) {
      fail("String_Node_Str");
    }
    System.out.println("String_Node_Str");
  }
 catch (  Exception anyother) {
    System.out.println("String_Node_Str");
    anyother.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * We should count the number of uploads in progress AND the number of uploads the upload queue before deciding the upload per host limit. Tests this. 
 */
public void testUploadLimtIncludesQueue(){
  UploadManager upManager=new UploadManager();
  setUploadManager(upManager);
  SettingsManager.instance().setMaxUploads(1);
  SettingsManager.instance().setSoftMaxUploads(1);
  SettingsManager.instance().setUploadsPerPerson(1);
  SettingsManager.instance().setUploadQueueSize(10);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    try {
      HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
      connectDloader(d2,true,rfd2,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      assertEquals(1,qx.getQueuePosition());
    }
catch (    Exception e) {
      fail("String_Node_Str");
    }
    try {
      HTTPDownloader d3=addUploader(upManager,rfd2,"String_Node_Str",true);
      connectDloader(d3,true,rfd2,true);
      fail("String_Node_Str");
    }
 catch (    QueuedException qx) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException talx) {
    }
catch (    IOException e) {
    }
catch (    Exception e) {
      fail("String_Node_Str");
    }
    System.out.println("String_Node_Str");
  }
 catch (  Exception anyother) {
    System.out.println("String_Node_Str");
    anyother.printStackTrace();
  }
}
Program: 4791
Project: 4791
Buggy source:
/** 
 * Tests that Uploader only queues downloaders that specify that they  support queueing
 */
public void testNotQueuedUnlessHeaderSent(){
  UploadManager upManager=new UploadManager();
  SettingsManager.instance().setMaxUploads(1);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(99999);
  SettingsManager.instance().setUploadQueueSize(1);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    try {
      connectDloader(d2,true,rfd2,false);
      fail("String_Node_Str");
    }
 catch (    QueuedException qe) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException expectedException) {
    }
catch (    IOException ioe) {
    }
    HTTPDownloader d3=addUploader(upManager,rfd3,"String_Node_Str",true);
    try {
      connectDloader(d3,true,rfd3,true);
      fail("String_Node_Str");
    }
 catch (    TryAgainLaterException tx) {
      fail("String_Node_Str");
    }
catch (    QueuedException expectedException) {
      assertEquals(1,expectedException.getQueuePosition());
    }
  }
 catch (  Exception anyOther) {
    System.out.println("String_Node_Str");
    anyOther.printStackTrace();
  }
  System.out.println("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Tests that Uploader only queues downloaders that specify that they  support queueing
 */
public void testNotQueuedUnlessHeaderSent(){
  UploadManager upManager=new UploadManager();
  setUploadManager(upManager);
  SettingsManager.instance().setMaxUploads(1);
  SettingsManager.instance().setSoftMaxUploads(9999);
  SettingsManager.instance().setUploadsPerPerson(99999);
  SettingsManager.instance().setUploadQueueSize(1);
  try {
    HTTPDownloader d1=addUploader(upManager,rfd1,"String_Node_Str",true);
    connectDloader(d1,true,rfd1,true);
    HTTPDownloader d2=addUploader(upManager,rfd2,"String_Node_Str",true);
    try {
      connectDloader(d2,true,rfd2,false);
      fail("String_Node_Str");
    }
 catch (    QueuedException qe) {
      fail("String_Node_Str");
    }
catch (    TryAgainLaterException expectedException) {
    }
catch (    IOException ioe) {
    }
    HTTPDownloader d3=addUploader(upManager,rfd3,"String_Node_Str",true);
    try {
      connectDloader(d3,true,rfd3,true);
      fail("String_Node_Str");
    }
 catch (    TryAgainLaterException tx) {
      fail("String_Node_Str");
    }
catch (    QueuedException expectedException) {
      assertEquals(1,expectedException.getQueuePosition());
    }
  }
 catch (  Exception anyOther) {
    System.out.println("String_Node_Str");
    anyOther.printStackTrace();
  }
  System.out.println("String_Node_Str");
}
Program: 4793
Project: 4793
Buggy source:
public void setUp(){
  ac=new ActivityCallbackStub();
  mr=new MessageRouterStub();
  fm=new FileManagerStub();
  a=new DummyAuthenticator();
  rs=new RouterService(ac);
  FileDesc fd=fm.get(0);
  rfd1=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd2=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd3=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd4=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd5=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
}

Fixed version (ground truth):
public void setUp(){
  ac=new ActivityCallbackStub();
  mr=new MessageRouterStub();
  fm=new FileManagerStub();
  a=new DummyAuthenticator();
  rs=new RouterService(ac);
  try {
    PrivilegedAccessor.setValue(rs,"String_Node_Str",fm);
  }
 catch (  Exception e) {
    fail("String_Node_Str");
  }
  FileDesc fd=fm.get(0);
  rfd1=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd2=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd3=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd4=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
  rfd5=new RemoteFileDesc("String_Node_Str",0,0,"String_Node_Str",1000000,new byte[16],56,false,3,false,null,null);
}
Program: 4795
Project: 4795
Buggy source:
/** 
 * Starts a "requery download", aka, a "wishlist download".  A "requery download" should be started when the user has not received any results for her query, and wants LimeWire to spawn a specialized Downloader that requeries the network until a 'appropriate' file is found.
 * @param query The original query string.
 * @param richQuery The original richQuery string.
 * @param guid The guid associated with this query request.
 * @param type The mediatype associated with this search.  
 */
public synchronized Downloader download(String query,String richQuery,byte[] guid,MediaType type) throws AlreadyDownloadingException {
  AutoDownloadDetails add=new AutoDownloadDetails(query,richQuery,guid,type);
  if (requeryConflicts(add))   throw new AlreadyDownloadingException(query);
  incompleteFileManager.purge(false);
  Downloader downloader=new RequeryDownloader(this,fileManager,incompleteFileManager,add,callback);
  waiting.add(downloader);
  callback.addDownload(downloader);
  writeSnapshot();
  return downloader;
}

Fixed version (ground truth):
/** 
 * Starts a "requery download", aka, a "wishlist download".  A "requery download" should be started when the user has not received any results for her query, and wants LimeWire to spawn a specialized Downloader that requeries the network until a 'appropriate' file is found.
 * @param query The original query string.
 * @param richQuery The original richQuery string.
 * @param guid The guid associated with this query request.
 * @param type The mediatype associated with this search.  
 */
public synchronized Downloader download(String query,String richQuery,byte[] guid,MediaType type) throws AlreadyDownloadingException {
  AutoDownloadDetails add=new AutoDownloadDetails(query,richQuery,guid,type);
  if (requeryConflicts(add))   throw new AlreadyDownloadingException(query);
  incompleteFileManager.purge(false);
  RequeryDownloader downloader=new RequeryDownloader(incompleteFileManager,add);
  downloader.initialize(this,fileManager,callback);
  waiting.add(downloader);
  callback.addDownload(downloader);
  writeSnapshot();
  return downloader;
}
Program: 4796
Project: 4796
Buggy source:
private void cleanup(){
  miniRFDToLock.clear();
  threadLockToSocket.clear();
  commonOutFile=null;
  if (needed != null)   needed.clear();
  busy=null;
  files=null;
}

Fixed version (ground truth):
private void cleanup(){
  miniRFDToLock.clear();
  threadLockToSocket.clear();
  if (needed != null)   needed.clear();
  busy=null;
  files=null;
}
Program: 4797
Project: 4797
Buggy source:
/** 
 * Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload(). Non-blocking.
 * @param manager the delegate for queueing purposes.  Also the callbackfor changes in state.
 * @param incompleteFileManager the repository of incomplete files forresuming
 */
public RequeryDownloader(DownloadManager manager,FileManager fileManager,IncompleteFileManager incompleteFileManager,AutoDownloadDetails add,ActivityCallback callback){
  super(manager,new RemoteFileDesc[0],fileManager,incompleteFileManager,callback);
  Assert.that(add != null,"String_Node_Str");
  _add=add;
}

Fixed version (ground truth):
/** 
 * Creates a new RequeryDownloader - a RequeryDownloader has no files initially associated with it, but it may have them later (via calls to addDownload().  Non-blocking.     
 * @param incompleteFileManager the repository of incomplete files forresuming
 * @param add the keywords to requery with
 */
public RequeryDownloader(IncompleteFileManager incompleteFileManager,AutoDownloadDetails add){
  super(new RemoteFileDesc[0],incompleteFileManager);
  Assert.that(add != null,"String_Node_Str");
  _add=add;
}
Program: 4798
Project: 4798
Buggy source:
/** 
 * Creates a RequeryDownloader to finish downloading incompleteFile.  This constructor has preconditions on several parameters; putting the burden on the caller makes the method easier to implement, since the superclass constructor immediately starts a download thread.
 * @param incompleteFile the incomplete file to resume to, whichMUST be the result of IncompleteFileManager.getFile.
 * @param name the name of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedName(incompleteFile)
 * @param size the size of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedSize(incompleteFile) 
 */
public ResumeDownloader(DownloadManager manager,FileManager fileManager,IncompleteFileManager incompleteFileManager,ActivityCallback callback,File incompleteFile,String name,int size){
  super(manager,new RemoteFileDesc[0],fileManager,incompleteFileManager,callback);
  this._incompleteFile=incompleteFile;
  this._name=name;
  this._size=size;
  this._hash=incompleteFileManager.getCompletedHash(incompleteFile);
}

Fixed version (ground truth):
/** 
 * Creates a RequeryDownloader to finish downloading incompleteFile.  This constructor has preconditions on several parameters; putting the burden on the caller makes the method easier to implement, since the superclass constructor immediately starts a download thread.
 * @param incompleteFile the incomplete file to resume to, whichMUST be the result of IncompleteFileManager.getFile.
 * @param name the name of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedName(incompleteFile)
 * @param size the size of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedSize(incompleteFile) 
 */
public ResumeDownloader(IncompleteFileManager incompleteFileManager,File incompleteFile,String name,int size){
  super(new RemoteFileDesc[0],incompleteFileManager);
  this._incompleteFile=incompleteFile;
  this._name=name;
  this._size=size;
  this._hash=incompleteFileManager.getCompletedHash(incompleteFile);
}
Program: 4799
Project: 4799
Buggy source:
private static RemoteFileDesc newRFD(String name,String hash){
  Set urns=null;
  if (hash != null) {
    urns=new HashSet(1);
    try {
      urns.add(URN.createSHA1Urn(hash));
    }
 catch (    IOException e) {
      fail("String_Node_Str");
    }
  }
  return new RemoteFileDesc("String_Node_Str",6346,13l,name,1024,new byte[16],56,false,4,true,null,urns);
}

Fixed version (ground truth):
private static RemoteFileDesc newRFD(String name,String hash){
  Set urns=null;
  if (hash != null) {
    urns=new HashSet(1);
    try {
      urns.add(URN.createSHA1Urn(hash));
    }
 catch (    IOException e) {
      fail("String_Node_Str");
    }
  }
  return new RemoteFileDesc("String_Node_Str",PORT,13l,name,1024,new byte[16],56,false,4,true,null,urns);
}
Program: 4800
Project: 4800
Buggy source:
public void testLegacy(){
  AutoDownloadDetails details=new AutoDownloadDetails("String_Node_Str","String_Node_Str",new byte[16],new MediaType("String_Node_Str","String_Node_Str",new String[0]));
  IncompleteFileManager ifm=new IncompleteFileManager();
  VerifyingFile vf=new VerifyingFile(true);
  vf.addInterval(new Interval(10,20));
  ifm.addEntry(new File("String_Node_Str"),vf);
  RequeryDownloader downloader=new RequeryDownloader(new DownloadManager(),new FileManager(),ifm,details,new ActivityCallbackStub());
  try {
    File tmp=File.createTempFile("String_Node_Str","String_Node_Str");
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(tmp));
    out.writeObject(downloader);
    out.close();
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(tmp));
    RequeryDownloader downloader2=(RequeryDownloader)in.readObject();
    in.close();
    assertTrue(downloader.hasFile() == downloader2.hasFile());
    tmp.delete();
  }
 catch (  IOException e) {
    e.printStackTrace();
    assertTrue("String_Node_Str",false);
  }
catch (  ClassNotFoundException e) {
    e.printStackTrace();
    assertTrue("String_Node_Str",false);
  }
}

Fixed version (ground truth):
public void testLegacy(){
  AutoDownloadDetails details=new AutoDownloadDetails("String_Node_Str","String_Node_Str",new byte[16],new MediaType("String_Node_Str","String_Node_Str",new String[0]));
  IncompleteFileManager ifm=new IncompleteFileManager();
  VerifyingFile vf=new VerifyingFile(true);
  vf.addInterval(new Interval(10,20));
  ifm.addEntry(new File("String_Node_Str"),vf);
  RequeryDownloader downloader=new RequeryDownloader(ifm,details);
  downloader.initialize(new DownloadManager(),new FileManager(),new ActivityCallbackStub());
  try {
    File tmp=File.createTempFile("String_Node_Str","String_Node_Str");
    ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(tmp));
    out.writeObject(downloader);
    out.close();
    ObjectInputStream in=new ObjectInputStream(new FileInputStream(tmp));
    RequeryDownloader downloader2=(RequeryDownloader)in.readObject();
    in.close();
    assertTrue(downloader.hasFile() == downloader2.hasFile());
    tmp.delete();
  }
 catch (  IOException e) {
    e.printStackTrace();
    assertTrue("String_Node_Str",false);
  }
catch (  ClassNotFoundException e) {
    e.printStackTrace();
    assertTrue("String_Node_Str",false);
  }
}
Program: 4801
Project: 4801
Buggy source:
/** 
 * Returns a new ResumeDownloader with stubbed-out DownloadManager, etc. 
 */
private static ResumeDownloader newResumeDownloader(){
  return new ResumeDownloader(new DownloadManagerStub(),new FileManagerStub(),ifm,new ActivityCallbackStub(),incompleteFile,name,size);
}

Fixed version (ground truth):
/** 
 * Returns a new ResumeDownloader with stubbed-out DownloadManager, etc. 
 */
private static ResumeDownloader newResumeDownloader(){
  ResumeDownloader ret=new ResumeDownloader(ifm,incompleteFile,name,size);
  ret.initialize(new DownloadManagerStub(),new FileManagerStub(),new ActivityCallbackStub());
  return ret;
}
Program: 4802
Project: 4802
Buggy source:
public void run(){
  try {
    Socket s=GIVuploader.connect();
    acceptUpload(HTTPRequestMethod.GET,s);
  }
 catch (  IOException ioe) {
synchronized (UploadManager.this) {
      insertFailedPush(host,index);
    }
  }
catch (  Exception e) {
    _callback.error(e);
  }
 finally {
    GIVuploader.stop();
synchronized (UploadManager.this) {
      removeAttemptingPush(host,index);
    }
  }
}

Fixed version (ground truth):
public void run(){
  try {
    Socket s=GIVuploader.connect();
    String word=IOUtils.readWord(s.getInputStream(),4);
    if (word.equals("String_Node_Str"))     acceptUpload(HTTPRequestMethod.GET,s);
 else     if (word.equals("String_Node_Str"))     acceptUpload(HTTPRequestMethod.HEAD,s);
 else     throw new IOException();
  }
 catch (  IOException ioe) {
synchronized (UploadManager.this) {
      insertFailedPush(host,index);
    }
  }
catch (  Exception e) {
    _callback.error(e);
  }
 finally {
    GIVuploader.stop();
synchronized (UploadManager.this) {
      removeAttemptingPush(host,index);
    }
  }
}
Program: 4804
Project: 4804
Buggy source:
/** 
 * This method is called in the case of a push only. <p> The method creates the socket, and send the GIV message. When this method returns the socket, is in the same state as a  socket created as a result of a normal upload - ready to receive GET <p>
 * @return The returned socket is used for a normal upload.
 */
public Socket connect() throws IOException {
  if (_socket != null)   return _socket;
  try {
    _socket=new Socket(_hostName,_port);
    _ostream=_socket.getOutputStream();
    Assert.that(_fileName != null);
    Assert.that(_fileName != "String_Node_Str");
    String giv="String_Node_Str" + _index + "String_Node_Str"+ _guid+ "String_Node_Str"+ _fileName+ "String_Node_Str";
    _ostream.write(giv.getBytes());
    _ostream.flush();
    InputStream in=_socket.getInputStream();
    String word=IOUtils.readWord(in,3);
    if (!word.equalsIgnoreCase("String_Node_Str"))     throw new IOException();
    return _socket;
  }
 catch (  SecurityException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IndexOutOfBoundsException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  NumberFormatException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IllegalArgumentException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IOException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
}

Fixed version (ground truth):
/** 
 * Establishes a push upload.  If this is already connected, returns immediately.  Otherwise attempts to establish a TCP connection to the remote host and send a GIV request.
 * @return this' underlying socket, for which a GIV has been sent butnothing has been read.  Typically the caller will read the GET or HEAD request from this socket.  The socket is needed for persistence and queueing purposes; caller must be careful when modifying it.
 * @throws IOException couldn't establish the connection
 */
public Socket connect() throws IOException {
  if (_socket != null)   return _socket;
  try {
    _socket=new Socket(_hostName,_port);
    _ostream=_socket.getOutputStream();
    Assert.that(_fileName != null);
    Assert.that(_fileName != "String_Node_Str");
    String giv="String_Node_Str" + _index + "String_Node_Str"+ _guid+ "String_Node_Str"+ _fileName+ "String_Node_Str";
    _ostream.write(giv.getBytes());
    _ostream.flush();
    return _socket;
  }
 catch (  SecurityException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IndexOutOfBoundsException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  NumberFormatException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IllegalArgumentException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
catch (  IOException e) {
    this.setState(Uploader.PUSH_FAILED);
    throw new IOException();
  }
}
Program: 4806
Project: 4806
Buggy source:
private static boolean downloadPush1(String file,String header,String expResp) throws IOException, BadPacketException {
  Connection c=new Connection(address,port);
  c.initialize();
  QueryRequest query=new QueryRequest((byte)5,0,"String_Node_Str");
  c.send(query);
  c.flush();
  QueryReply reply=null;
  while (true) {
    Message m=c.receive(2000);
    if (m instanceof QueryReply) {
      reply=(QueryReply)m;
      break;
    }
  }
  PushRequest push=new PushRequest(GUID.makeGuid(),(byte)5,reply.getClientGUID(),0,new byte[]{(byte)127,(byte)0,(byte)0,(byte)1},callbackPort);
  ServerSocket ss=new ServerSocket(callbackPort);
  c.send(push);
  c.flush();
  Socket s=ss.accept();
  BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
  BufferedWriter out=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
  in.readLine();
  in.readLine();
  String retStr=downloadInternal1(file,header,out,in,expResp.length());
  assertEquals("String_Node_Str",expResp,retStr);
  boolean ret=retStr.equals(expResp);
  retStr=downloadInternal1(file,header,out,in,expResp.length());
  assertEquals("String_Node_Str",expResp,retStr);
  ret=ret && retStr.equals(expResp);
  c.close();
  s.close();
  ss.close();
  return ret;
}

Fixed version (ground truth):
/** 
 * Does an arbitrary push download. 
 * @param request an HTTP request such as "GET" or "HEAD"
 * @param file the full filename, e.g., "/get/0/file.txt"    
 */
private static boolean downloadPush1(String request,String file,String header,String expResp) throws IOException, BadPacketException {
  Connection c=new Connection(address,port);
  c.initialize();
  QueryRequest query=new QueryRequest((byte)5,0,"String_Node_Str");
  c.send(query);
  c.flush();
  QueryReply reply=null;
  while (true) {
    Message m=c.receive(2000);
    if (m instanceof QueryReply) {
      reply=(QueryReply)m;
      break;
    }
  }
  PushRequest push=new PushRequest(GUID.makeGuid(),(byte)5,reply.getClientGUID(),0,new byte[]{(byte)127,(byte)0,(byte)0,(byte)1},callbackPort);
  ServerSocket ss=new ServerSocket(callbackPort);
  c.send(push);
  c.flush();
  Socket s=ss.accept();
  BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
  BufferedWriter out=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
  in.readLine();
  in.readLine();
  String retStr=downloadInternal1(request,file,header,out,in,expResp.length());
  assertEquals("String_Node_Str",expResp,retStr);
  boolean ret=retStr.equals(expResp);
  retStr=downloadInternal1(request,file,header,out,in,expResp.length());
  assertEquals("String_Node_Str",expResp,retStr);
  ret=ret && retStr.equals(expResp);
  c.close();
  s.close();
  ss.close();
  return ret;
}
Program: 4807
Project: 4807
Buggy source:
/** 
 * @return true if the number of uploads from the host is strictly LESS thanthe MAX, although we want to allow exactly MAX uploads from the same host. This is because this method is called BEFORE we add/allow the. upload.
 */
private synchronized boolean hostLimitReached(String host){
  int max=SettingsManager.instance().getUploadsPerPerson();
  int i=0;
  Iterator iter=_activeUploadList.iterator();
  while (iter.hasNext()) {
    Uploader u=(Uploader)iter.next();
    if (u.getHost().equals(host))     i++;
  }
  return i >= max;
}

Fixed version (ground truth):
/** 
 * @return true if the number of uploads from the host is strictly LESS thanthe MAX, although we want to allow exactly MAX uploads from the same host. This is because this method is called BEFORE we add/allow the. upload.
 */
private synchronized boolean hostLimitReached(String host){
  int max=SettingsManager.instance().getUploadsPerPerson();
  int i=0;
  Iterator iter=_activeUploadList.iterator();
  while (iter.hasNext()) {
    Uploader u=(Uploader)iter.next();
    if (u.getHost().equals(host))     i++;
  }
  iter=_queuedUploads.iterator();
  while (iter.hasNext()) {
    Socket s=(Socket)((KeyValue)iter.next()).getKey();
    if (s.getInetAddress().getHostAddress().equals(host))     i++;
  }
  return i >= max;
}
Program: 4809
Project: 4809
Buggy source:
/** 
 * Returns the name of the complete file associated with the given incomplete file, i.e., what incompleteFile will be renamed to when the download completes (without path information).
 * @param incompleteFile a file returned by getFile
 * @return the complete file name, without path
 * @exception IllegalArgumentException incompleteFile was not thereturn value from getFile
 */
public static String getCompletedName(File incompleteFile) throws IllegalArgumentException {
  String name=incompleteFile.getName();
  int i=name.indexOf(SEPARATOR);
  if (i < 0)   throw new IllegalArgumentException("String_Node_Str" + name);
  int j=name.indexOf(SEPARATOR,i + 1);
  if (j < 0)   throw new IllegalArgumentException("String_Node_Str" + name);
  if (j == name.length() - 1)   throw new IllegalArgumentException("String_Node_Str");
  return name.substring(j + 1);
}

Fixed version (ground truth):
/** 
 * Returns the name of the complete file associated with the given incomplete file, i.e., what incompleteFile will be renamed to when the download completes (without path information).  Slow; runs in linear time with respect to the number of hashes in this.
 * @param incompleteFile a file returned by getFile
 * @return the complete file name, without path
 * @exception IllegalArgumentException incompleteFile was not thereturn value from getFile
 */
public static String getCompletedName(File incompleteFile) throws IllegalArgumentException {
  String name=incompleteFile.getName();
  int i=name.indexOf(SEPARATOR);
  if (i < 0)   throw new IllegalArgumentException("String_Node_Str" + name);
  int j=name.indexOf(SEPARATOR,i + 1);
  if (j < 0)   throw new IllegalArgumentException("String_Node_Str" + name);
  if (j == name.length() - 1)   throw new IllegalArgumentException("String_Node_Str");
  return name.substring(j + 1);
}
Program: 4810
Project: 4810
Buggy source:
public QueryRequest newRequery(){
  URN hash=_incompleteFileManager.getCompletedHash(_incompleteFile);
  Set queryUrns=null;
  if (hash != null) {
    queryUrns=new HashSet(1);
    queryUrns.add(hash);
  }
  return new QueryRequest(QueryRequest.newQueryGUID(true),(byte)7,0,getFileName(),null,true,null,queryUrns);
}

Fixed version (ground truth):
public QueryRequest newRequery(){
  Set queryUrns=null;
  if (_hash != null) {
    queryUrns=new HashSet(1);
    queryUrns.add(_hash);
  }
  return new QueryRequest(QueryRequest.newQueryGUID(true),(byte)7,0,getFileName(),null,true,null,queryUrns);
}
Program: 4811
Project: 4811
Buggy source:
/** 
 * Creates a RequeryDownloader to finish downloading incompleteFile.  This constructor has preconditions on several parameters; putting the burden on the caller makes the method easier to implement, since the superclass constructor immediately starts a download thread.
 * @param incompleteFile the incomplete file to resume to, whichMUST be the result of IncompleteFileManager.getFile.
 * @param name the name of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedName(incompleteFile)
 * @param size the size of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedSize(incompleteFile) 
 */
public ResumeDownloader(DownloadManager manager,FileManager fileManager,IncompleteFileManager incompleteFileManager,ActivityCallback callback,File incompleteFile,String name,int size){
  super(manager,new RemoteFileDesc[0],fileManager,incompleteFileManager,callback);
  this._incompleteFileManager=incompleteFileManager;
  this._incompleteFile=incompleteFile;
  this._name=name;
  this._size=size;
}

Fixed version (ground truth):
/** 
 * Creates a RequeryDownloader to finish downloading incompleteFile.  This constructor has preconditions on several parameters; putting the burden on the caller makes the method easier to implement, since the superclass constructor immediately starts a download thread.
 * @param incompleteFile the incomplete file to resume to, whichMUST be the result of IncompleteFileManager.getFile.
 * @param name the name of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedName(incompleteFile)
 * @param size the size of the completed file, which MUST be the result ofIncompleteFileManager.getCompletedSize(incompleteFile) 
 */
public ResumeDownloader(DownloadManager manager,FileManager fileManager,IncompleteFileManager incompleteFileManager,ActivityCallback callback,File incompleteFile,String name,int size){
  super(manager,new RemoteFileDesc[0],fileManager,incompleteFileManager,callback);
  this._incompleteFile=incompleteFile;
  this._name=name;
  this._size=size;
  this._hash=incompleteFileManager.getCompletedHash(incompleteFile);
}
Program: 4812
Project: 4812
Buggy source:
/** 
 * Overrides ManagedDownloader to allow any RemoteFileDesc that would resume from _incompleteFile.
 */
protected boolean allowAddition(RemoteFileDesc other){
  return _incompleteFile.equals(_incompleteFileManager.getFile(other));
}

Fixed version (ground truth):
/** 
 * Overrides ManagedDownloader to allow any RemoteFileDesc that would resume from _incompleteFile.
 */
protected boolean allowAddition(RemoteFileDesc other){
  return IncompleteFileManager.same(_name,_size,_hash,other.getFileName(),other.getSize(),other.getSHA1Urn());
}
Program: 4813
Project: 4813
Buggy source:
public static Test suite(){
  TestSuite suite=new TestSuite("String_Node_Str");
  suite.addTest(RemoteFileDescGrouperTest.suite());
  suite.addTest(DownloadTest.suite());
  suite.addTest(ManagedDownloaderTest.suite());
  suite.addTest(TestOldDownloads.suite());
  suite.addTest(HTTPDownloaderTest.suite());
  suite.addTest(IntervalTest.suite());
  suite.addTest(MiniRemoteFileDescTest.suite());
  suite.addTest(RequeryDownloaderTest.suite());
  suite.addTest(RequeryDownloadTest.suite());
  suite.addTest(IncompleteFileManagerTest.suite());
  suite.addTest(AutoDownloaderDetailsTest.suite());
  return suite;
}

Fixed version (ground truth):
public static Test suite(){
  TestSuite suite=new TestSuite("String_Node_Str");
  suite.addTest(RemoteFileDescGrouperTest.suite());
  suite.addTest(DownloadTest.suite());
  suite.addTest(ManagedDownloaderTest.suite());
  suite.addTest(TestOldDownloads.suite());
  suite.addTest(HTTPDownloaderTest.suite());
  suite.addTest(IntervalTest.suite());
  suite.addTest(MiniRemoteFileDescTest.suite());
  suite.addTest(RequeryDownloaderTest.suite());
  suite.addTest(ResumeDownloaderTest.suite());
  suite.addTest(RequeryDownloadTest.suite());
  suite.addTest(IncompleteFileManagerTest.suite());
  suite.addTest(AutoDownloaderDetailsTest.suite());
  return suite;
}
Program: 4814
Project: 4814
Buggy source:
/** 
 * Different name or size ==> different temp file 
 */
public void testGetFile_DifferentSize(){
  rfd1=newRFD("String_Node_Str",1839,null);
  rfd2=newRFD("String_Node_Str",1223,null);
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertTrue(!tmp2.equals(tmp1));
}

Fixed version (ground truth):
/** 
 * Different name or size ==> different temp file 
 */
public void testGetFile_DifferentSize(){
  rfd1=newRFD("String_Node_Str",1839,null);
  rfd2=newRFD("String_Node_Str",1223,null);
  assertTrue(!IncompleteFileManager.same(rfd1,rfd2));
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertTrue(!tmp2.equals(tmp1));
}
Program: 4815
Project: 4815
Buggy source:
/** 
 * Risky resumes are allowed: no hashes 
 */
public void testGetFile_NoHash(){
  rfd1=newRFD("String_Node_Str",1839,null);
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertEquals(tmp1,tmp2);
}

Fixed version (ground truth):
/** 
 * Risky resumes are allowed: no hashes 
 */
public void testGetFile_NoHash(){
  rfd1=newRFD("String_Node_Str",1839,null);
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  assertTrue(IncompleteFileManager.same(rfd1,rfd2));
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertEquals(tmp1,tmp2);
}
Program: 4816
Project: 4816
Buggy source:
/** 
 * You should NOT be able to resume to file w/ same name but different hash.
 */
public void testGetFile_SameNameDifferentHash(){
  rfd1=newRFD("String_Node_Str",1839,"String_Node_Str");
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertTrue(!tmp2.equals(tmp1));
}

Fixed version (ground truth):
/** 
 * You should NOT be able to resume to file w/ same name but different hash.
 */
public void testGetFile_SameNameDifferentHash(){
  rfd1=newRFD("String_Node_Str",1839,"String_Node_Str");
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  assertTrue(!IncompleteFileManager.same(rfd1,rfd2));
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertTrue(!tmp2.equals(tmp1));
}
Program: 4817
Project: 4817
Buggy source:
/** 
 * You should be able to resume to a file with same hash but different name.
 */
public void testGetFile_DifferentNameSameHash(){
  rfd1=newRFD("String_Node_Str",1839,"String_Node_Str");
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertEquals(tmp1,tmp2);
}

Fixed version (ground truth):
/** 
 * You should be able to resume to a file with same hash but different name.
 */
public void testGetFile_DifferentNameSameHash(){
  rfd1=newRFD("String_Node_Str",1839,"String_Node_Str");
  rfd2=newRFD("String_Node_Str",1839,"String_Node_Str");
  assertTrue(IncompleteFileManager.same(rfd1,rfd2));
  File tmp1=ifm.getFile(rfd1);
  File tmp2=ifm.getFile(rfd2);
  assertEquals(tmp1,tmp2);
}
Program: 4819
Project: 4819
Buggy source:
/** 
 * Note: Called when we encounter a 503, and need to check if the uploader has queued us or not. Consuming all the headers is required, because if queued, we intend to use the same stream again, and residual headers will cause problems. Further, these headers are of no use to anyone else.
 */
private void supportsQueueing() throws IOException, QueuedException {
  int position=-1;
  int minPollTime=-1;
  int maxPollTime=-1;
  String str=_byteReader.readLine();
  while (!str.equals("String_Node_Str")) {
    StringTokenizer tokenizer=new StringTokenizer(str,"String_Node_Str");
    if (!tokenizer.hasMoreTokens()) {
      str=_byteReader.readLine();
      continue;
    }
    String token=tokenizer.nextToken();
    if (!token.equals("String_Node_Str")) {
      str=_byteReader.readLine();
      continue;
    }
    while (tokenizer.hasMoreTokens()) {
      token=tokenizer.nextToken();
      String value;
      if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        minPollTime=Integer.parseInt(value);
      }
 else       if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        maxPollTime=Integer.parseInt(value);
      }
 else       if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        position=Integer.parseInt(value);
      }
    }
    str=_byteReader.readLine();
  }
  if (minPollTime == -1 && maxPollTime == -1 && position == -1)   throw new IOException();
  throw new QueuedException(minPollTime,maxPollTime,position);
}

Fixed version (ground truth):
/** 
 * Note: Called when we encounter a 503, and need to check if the uploader has queued us or not. Consuming all the headers is required, because if queued, we intend to use the same stream again, and residual headers will cause problems. Further, these headers are of no use to anyone else.
 */
private void supportsQueueing() throws IOException, QueuedException {
  int position=-1;
  int minPollTime=-1;
  int maxPollTime=-1;
  String str=_byteReader.readLine();
  if (str == null)   throw new IOException();
  while (!str.equals("String_Node_Str")) {
    StringTokenizer tokenizer=new StringTokenizer(str,"String_Node_Str");
    if (!tokenizer.hasMoreTokens()) {
      str=_byteReader.readLine();
      continue;
    }
    String token=tokenizer.nextToken();
    if (!token.equals("String_Node_Str")) {
      str=_byteReader.readLine();
      continue;
    }
    while (tokenizer.hasMoreTokens()) {
      token=tokenizer.nextToken();
      String value;
      if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        minPollTime=Integer.parseInt(value);
      }
 else       if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        maxPollTime=Integer.parseInt(value);
      }
 else       if (token.equals("String_Node_Str")) {
        value=tokenizer.nextToken();
        position=Integer.parseInt(value);
      }
    }
    str=_byteReader.readLine();
  }
  if (minPollTime == -1 && maxPollTime == -1 && position == -1)   throw new IOException();
  throw new QueuedException(minPollTime,maxPollTime,position);
}
Program: 4822
Project: 4822
Buggy source:
/** 
 * Sends a get request to out, reads the response from in, and returns the content.  Doesn't close in or out.
 */
private static String downloadInternal1(String file,String header,BufferedWriter out,BufferedReader in,int expectedSize) throws IOException {
  out.write("String_Node_Str" + index + "String_Node_Str"+ file+ "String_Node_Str");
  if (header != null)   out.write(header + "String_Node_Str");
  out.write("String_Node_Str");
  out.write("String_Node_Str");
  out.flush();
  while (!in.readLine().equals("String_Node_Str")) {
  }
  StringBuffer buf=new StringBuffer();
  for (int i=0; i < expectedSize; i++) {
    int c=in.read();
    buf.append((char)c);
  }
  return buf.toString();
}

Fixed version (ground truth):
/** 
 * Same as downloadInternal1(file, header, out, in, expectedSize), but uses the given request type.
 * @param request an HTTP request such as "GET" or "HEAD"
 */
private static String downloadInternal1(String request,String file,String header,BufferedWriter out,BufferedReader in,int expectedSize) throws IOException {
  out.write(request + "String_Node_Str" + index+ "String_Node_Str"+ file+ "String_Node_Str");
  if (header != null)   out.write(header + "String_Node_Str");
  out.write("String_Node_Str");
  out.write("String_Node_Str");
  out.flush();
  while (!in.readLine().equals("String_Node_Str")) {
  }
  StringBuffer buf=new StringBuffer();
  for (int i=0; i < expectedSize; i++) {
    int c=in.read();
    buf.append((char)c);
  }
  return buf.toString();
}
Program: 4823
Project: 4823
Buggy source:
protected void setUp(){
  try {
    address=InetAddress.getLocalHost().getHostAddress();
  }
 catch (  UnknownHostException e) {
    assertTrue("String_Node_Str" + e,false);
  }
  port=6668;
  File testDir=new File("String_Node_Str");
  if (!testDir.isDirectory()) {
    testDir=new File("String_Node_Str");
  }
  assertTrue("String_Node_Str",testDir.isDirectory());
  assertTrue("String_Node_Str",new File(testDir,file).isFile());
  SettingsManager.instance().setPort(port);
  SettingsManager.instance().setDirectories(new File[]{testDir});
  SettingsManager.instance().setExtensions("String_Node_Str");
  SettingsManager.instance().setKeepAlive(6);
  SettingsManager.instance().setMaxUploads(10);
  SettingsManager.instance().setUploadsPerPerson(10);
  SettingsManager.instance().setConnectOnStartup(true);
  SettingsManager.instance().writeProperties();
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager fm=new MetaFileManager();
  fm.initialize(callback);
  MessageRouter mr=new StandardMessageRouter(callback,fm);
  RouterService router=new RouterService(callback,mr,fm,new ServerAuthenticator());
  router.initialize();
  assertEquals(port,SettingsManager.instance().getPort());
}

Fixed version (ground truth):
protected void setUp(){
  try {
    address=InetAddress.getLocalHost().getHostAddress();
  }
 catch (  UnknownHostException e) {
    assertTrue("String_Node_Str" + e,false);
  }
  port=6668;
  File testDir=new File("String_Node_Str");
  if (!testDir.isDirectory()) {
    testDir=new File("String_Node_Str");
  }
  assertTrue("String_Node_Str",testDir.isDirectory());
  assertTrue("String_Node_Str",new File(testDir,file).isFile());
  SettingsManager.instance().setPort(port);
  SettingsManager.instance().setDirectories(new File[]{testDir});
  SettingsManager.instance().setExtensions("String_Node_Str");
  SettingsManager.instance().setKeepAlive(8);
  SettingsManager.instance().setMaxUploads(10);
  SettingsManager.instance().setUploadsPerPerson(10);
  SettingsManager.instance().setConnectOnStartup(true);
  SettingsManager.instance().setFilterDuplicates(false);
  SettingsManager.instance().setEverSupernodeCapable(true);
  SettingsManager.instance().setForceSupernodeMode(true);
  SettingsManager.instance().setDisableSupernodeMode(false);
  SettingsManager.instance().writeProperties();
  ActivityCallback callback=new ActivityCallbackStub();
  FileManager fm=new MetaFileManager();
  fm.initialize(callback);
  MessageRouter mr=new StandardMessageRouter(callback,fm);
  RouterService router=new RouterService(callback,mr,fm,new ServerAuthenticator());
  router.initialize();
  assertEquals(port,SettingsManager.instance().getPort());
}
Program: 4825
Project: 4825
Buggy source:
public String getValue(String fieldName){
  String retValue=null;
  fieldName=fieldName.trim();
  retValue=(String)fieldToValue.get(fieldName);
  if (fieldName.equals("String_Node_Str") && (retValue != null)) {
    try {
      short index=Short.parseShort(retValue);
      retValue=ID3Reader.getGenreString(index);
      fieldToValue.put(fieldName,retValue);
    }
 catch (    NumberFormatException ignored) {
    }
 finally {
      if (retValue.equals("String_Node_Str")) {
        fieldToValue.remove(fieldName);
        retValue=null;
      }
    }
  }
  return retValue;
}

Fixed version (ground truth):
public String getValue(String fieldName){
  String retValue=null;
  fieldName=fieldName.trim();
  retValue=(String)fieldToValue.get(fieldName);
  if (fieldName.equals("String_Node_Str") && (retValue != null)) {
    try {
      short index=Short.parseShort(retValue);
      retValue=ID3Reader.getGenreString(index);
      fieldToValue.put(fieldName,retValue);
    }
 catch (    NumberFormatException ignored) {
    }
  }
  return retValue;
}
Program: 4828
Project: 4828
Buggy source:
public File getDownloadFragment(){
  if (currentFileName == null)   return null;
  if (state == CORRUPT_FILE)   return corruptFile;
 else   if (state != COMPLETE) {
    RemoteFileDesc rfd=buckets.getRemoteFileDescForBucket(bucketNumber);
    File incomplete=incompleteFileManager.getFile(rfd);
    File file=new File(incomplete.getParent(),IncompleteFileManager.PREVIEW_PREFIX + incomplete.getName());
    int size=amountForPreview();
    if (size <= 0)     return null;
    if (CommonUtils.copy(incomplete,size,file) <= 0)     return null;
    return file;
  }
 else {
    File saveDir=null;
    try {
      saveDir=SettingsManager.instance().getSaveDirectory();
    }
 catch (    java.io.FileNotFoundException fnfe) {
      return null;
    }
    return new File(saveDir,currentFileName);
  }
}

Fixed version (ground truth):
public File getDownloadFragment(){
  if (incompleteFile == null)   return null;
  if (state == CORRUPT_FILE)   return corruptFile;
 else   if (state != COMPLETE) {
    File file=new File(incompleteFile.getParent(),IncompleteFileManager.PREVIEW_PREFIX + incompleteFile.getName());
    int size=amountForPreview();
    if (size <= 0)     return null;
    if (CommonUtils.copy(incompleteFile,size,file) <= 0)     return null;
    return file;
  }
 else {
    return completeFile;
  }
}
Program: 4832
Project: 4832
Buggy source:
/** 
 * Returns the <tt>UrnCache</tt> instance.
 * @return the <tt>UrnCache</tt> instance
 */
public static UrnCache instance(){
  if (instance == null) {
    instance=new UrnCache();
  }
  return instance;
}

Fixed version (ground truth):
/** 
 * Returns the <tt>UrnCache</tt> instance.
 * @return the <tt>UrnCache</tt> instance
 */
public static synchronized UrnCache instance(){
  if (instance == null) {
    instance=new UrnCache();
  }
  return instance;
}