Program: 4357
Project: 4357
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 void establishConnection(){
  if (LOG.isTraceEnabled())   LOG.trace("String_Node_Str" + _rfd + "String_Node_Str");
  if (_rfd == null)   return;
  if (_manager.isCancelled() || _manager.isPaused()) {
    _manager.addRFD(_rfd);
    return;
  }
  boolean needsPush=_rfd.needsPush();
synchronized (_manager) {
    int state=_manager.getState();
    if (_manager.getNumDownloaders() == 0 && state != ManagedDownloader.COMPLETE && state != ManagedDownloader.ABORTED && state != ManagedDownloader.GAVE_UP && state != ManagedDownloader.DISK_PROBLEM && state != ManagedDownloader.CORRUPT_FILE && state != ManagedDownloader.HASHING && state != ManagedDownloader.SAVING) {
      if (_interrupted)       return;
      _manager.setState(ManagedDownloader.CONNECTING,needsPush ? PUSH_CONNECT_TIME : NORMAL_CONNECT_TIME);
    }
  }
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + _rfd.getHost() + "String_Node_Str"+ _rfd.getPort());
  DownloadStat.CONNECTION_ATTEMPTS.incrementStat();
  if (_rfd.isReplyToMulticast()) {
    try {
      _downloader=connectWithPush();
    }
 catch (    IOException e) {
      try {
        _downloader=connectDirectly();
      }
 catch (      IOException e2) {
        return;
      }
    }
    return;
  }
  if (!needsPush) {
    try {
      _downloader=connectDirectly();
    }
 catch (    IOException e) {
    }
  }
  if (_downloader == null) {
    try {
      _downloader=connectWithPush();
    }
 catch (    IOException e) {
      _manager.forgetRFD(_rfd);
    }
  }
  if (_downloader == null)   _manager.informMesh(_rfd,false);
 else   if (_interrupted) {
    _downloader.stop();
    _downloader=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 void establishConnection(){
  if (LOG.isTraceEnabled())   LOG.trace("String_Node_Str" + _rfd + "String_Node_Str");
  if (_rfd == null)   return;
  if (_manager.isCancelled() || _manager.isPaused()) {
    _manager.addRFD(_rfd);
    return;
  }
  boolean needsPush=_rfd.needsPush();
synchronized (_manager) {
    int state=_manager.getState();
    if (_manager.getNumDownloaders() == 0 && state != ManagedDownloader.COMPLETE && state != ManagedDownloader.ABORTED && state != ManagedDownloader.GAVE_UP && state != ManagedDownloader.DISK_PROBLEM && state != ManagedDownloader.CORRUPT_FILE && state != ManagedDownloader.HASHING && state != ManagedDownloader.SAVING) {
      if (_interrupted)       return;
      _manager.setState(ManagedDownloader.CONNECTING,needsPush ? PUSH_CONNECT_TIME : NORMAL_CONNECT_TIME);
    }
  }
  if (LOG.isDebugEnabled())   LOG.debug("String_Node_Str" + _rfd.getHost() + "String_Node_Str"+ _rfd.getPort());
  DownloadStat.CONNECTION_ATTEMPTS.incrementStat();
  if (_rfd.isReplyToMulticast()) {
    try {
      _downloader=connectWithPush();
    }
 catch (    IOException e) {
      try {
        _downloader=connectDirectly();
      }
 catch (      IOException e2) {
        return;
      }
    }
    return;
  }
  if (!needsPush) {
    try {
      _downloader=connectDirectly();
    }
 catch (    IOException e) {
    }
  }
  if (_downloader == null) {
    try {
      _downloader=connectWithPush();
    }
 catch (    IOException e) {
      if (needsPush)       _manager.forgetRFD(_rfd);
    }
  }
  if (_downloader == null)   _manager.informMesh(_rfd,false);
 else   if (_interrupted) {
    _downloader.stop();
    _downloader=null;
  }
}