Program: 4610
Project: 4610
Buggy source:
/** 
 * Returns an un-initialized (only established a TCP Connection,  no HTTP headers have been exchanged yet) connectable downloader  from the given list of locations. <p>  method tries to establish connection either by push or by normal ways. <p> If the connection fails for some reason, or needs a push the mesh needs  to be informed that this location failed.
 * @param rfd the RemoteFileDesc to connect to<p>  The following exceptions may be thrown within this method, but they are all dealt with internally. So this method does not throw any exception <p> NoSuchElementException thrown when (both normal and push) connections  to the given rfd fail. We discard the rfd by doing nothing and return  null.
 * @exception InterruptedException this thread was interrupted while waitingto connect. Remember this rfd by putting it back into files and return null 
 */
private HTTPDownloader establishConnection(RemoteFileDesc rfd){
  if (rfd == null)   return null;
  if (stopped) {
synchronized (this) {
      files.add(rfd);
    }
    return null;
  }
  File incFile=incompleteFileManager.getFile(rfd);
  HTTPDownloader ret;
  boolean needsPush=needsPush(rfd);
synchronized (this) {
    currentLocation=rfd.getHost();
    if (dloaders.size() == 0 && getState() != COMPLETE && getState() != ABORTED && getState() != GAVE_UP && getState() != COULDNT_MOVE_TO_LIBRARY && getState() != CORRUPT_FILE && getState() != HASHING && getState() != SAVING && queuedCount == 0)     setState(CONNECTING,needsPush ? PUSH_CONNECT_TIME : NORMAL_CONNECT_TIME);
  }
  debug("String_Node_Str" + rfd.getHost() + "String_Node_Str"+ rfd.getPort());
  if (RECORD_STATS)   DownloadStat.CONNECTION_ATTEMPTS.incrementStat();
  if (rfd.isReplyToMulticast()) {
    try {
      ret=connectWithPush(rfd,incFile);
    }
 catch (    IOException e) {
      try {
        ret=connectDirectly(rfd,incFile);
      }
 catch (      IOException e2) {
        informMesh(rfd,false);
        return null;
      }
    }
    return ret;
  }
  if (!needsPush) {
    try {
      ret=connectDirectly(rfd,incFile);
      return ret;
    }
 catch (    IOException e) {
      informMesh(rfd,false);
    }
  }
  try {
    ret=connectWithPush(rfd,incFile);
    return ret;
  }
 catch (  IOException e) {
  }
  informMesh(rfd,false);
  return null;
}

Fixed version (ground truth):
/** 
 * Returns an un-initialized (only established a TCP Connection,  no HTTP headers have been exchanged yet) connectable downloader  from the given list of locations. <p>  method tries to establish connection either by push or by normal ways. <p> If the connection fails for some reason, or needs a push the mesh needs  to be informed that this location failed.
 * @param rfd the RemoteFileDesc to connect to<p>  The following exceptions may be thrown within this method, but they are all dealt with internally. So this method does not throw any exception <p> NoSuchElementException thrown when (both normal and push) connections  to the given rfd fail. We discard the rfd by doing nothing and return  null.
 * @exception InterruptedException this thread was interrupted while waitingto connect. Remember this rfd by putting it back into files and return null 
 */
private HTTPDownloader establishConnection(RemoteFileDesc rfd){
  if (rfd == null)   return null;
  if (stopped) {
synchronized (this) {
      files.add(rfd);
    }
    return null;
  }
  File incFile=incompleteFileManager.getFile(rfd);
  HTTPDownloader ret;
  boolean needsPush=needsPush(rfd);
synchronized (this) {
    currentLocation=rfd.getHost();
    if (dloaders.size() == 0 && getState() != COMPLETE && getState() != ABORTED && getState() != GAVE_UP && getState() != COULDNT_MOVE_TO_LIBRARY && getState() != CORRUPT_FILE && getState() != HASHING && getState() != SAVING && queuedCount == 0)     setState(CONNECTING,needsPush ? PUSH_CONNECT_TIME : NORMAL_CONNECT_TIME);
  }
  debug("String_Node_Str" + rfd.getHost() + "String_Node_Str"+ rfd.getPort());
  if (RECORD_STATS)   DownloadStat.CONNECTION_ATTEMPTS.incrementStat();
  if (rfd.isReplyToMulticast()) {
    try {
      ret=connectWithPush(rfd,incFile);
    }
 catch (    IOException e) {
      try {
        ret=connectDirectly(rfd,incFile);
      }
 catch (      IOException e2) {
        return null;
      }
    }
    return ret;
  }
  if (!needsPush) {
    try {
      ret=connectDirectly(rfd,incFile);
      return ret;
    }
 catch (    IOException e) {
    }
  }
  informMesh(rfd,false);
  try {
    ret=connectWithPush(rfd,incFile);
    return ret;
  }
 catch (  IOException e) {
  }
  return null;
}