Program: 4568
Project: 4568
Buggy source:
/** 
 * Initialize the connection by doing the handshake.  Throws IOException if we were unable to establish a normal messaging connection for any reason.  Do not call send or receive if this happens.
 * @param timeout for outgoing connections, the timeout in millisecondsto use in establishing the socket, or 0 for no timeout.  If the  platform does not support native timeouts, it will be emulated with threads.
 * @exception IOException we were unable to connect to the host
 * @exception NoGnutellaOkException one of the participants respondedwith an error code other than 200 OK (possibly after several rounds of 401's)
 * @exception BadHandshakeException some other problem establishing the connection, e.g., the server responded with HTTP, closed the the connection during handshaking, etc.
 */
public void initialize(int timeout) throws IOException, NoGnutellaOkException, BadHandshakeException {
  if (isOutgoing())   _socket=Sockets.connect(_host,_port,timeout);
  if (_closed) {
    _socket.close();
    throw CONNECTION_CLOSED;
  }
  InetAddress localAddress=_socket.getLocalAddress();
  if (ConnectionSettings.LOCAL_IS_PRIVATE.getValue() && _socket.getInetAddress().equals(localAddress) && _port == ConnectionSettings.PORT.getValue()) {
    throw new IOException("String_Node_Str");
  }
  try {
    RouterService.getAcceptor().setAddress(localAddress);
    _in=getInputStream();
    _out=getOutputStream();
    if (_in == null)     throw new IOException("String_Node_Str");
 else     if (_out == null)     throw new IOException("String_Node_Str");
  }
 catch (  Exception e) {
    close();
    throw new IOException("String_Node_Str");
  }
  try {
    if (isOutgoing())     initializeOutgoing();
 else     initializeIncoming();
    _headers=HandshakeResponse.createResponse(HEADERS_READ);
    _headersWritten=HandshakeResponse.createResponse(HEADERS_WRITTEN);
    _connectionTime=System.currentTimeMillis();
    _softMax=ConnectionSettings.SOFT_MAX.getValue();
    if (isGoodUltrapeer() || isGoodLeaf()) {
      _softMax++;
    }
    if (isWriteDeflated()) {
      _deflater=new Deflater();
      _out=new CompressingOutputStream(_out,_deflater);
    }
    if (isReadDeflated()) {
      _inflater=new Inflater();
      _in=new UncompressingInputStream(_in,_inflater);
    }
    RESPONSE_HEADERS=null;
  }
 catch (  NoGnutellaOkException e) {
    close();
    throw e;
  }
catch (  IOException e) {
    close();
    throw new BadHandshakeException(e);
  }
}

Fixed version (ground truth):
/** 
 * Initialize the connection by doing the handshake.  Throws IOException if we were unable to establish a normal messaging connection for any reason.  Do not call send or receive if this happens.
 * @param timeout for outgoing connections, the timeout in millisecondsto use in establishing the socket, or 0 for no timeout.  If the  platform does not support native timeouts, it will be emulated with threads.
 * @exception IOException we were unable to connect to the host
 * @exception NoGnutellaOkException one of the participants respondedwith an error code other than 200 OK (possibly after several rounds of 401's)
 * @exception BadHandshakeException some other problem establishing the connection, e.g., the server responded with HTTP, closed the the connection during handshaking, etc.
 */
public void initialize(int timeout) throws IOException, NoGnutellaOkException, BadHandshakeException {
  if (isOutgoing())   _socket=Sockets.connect(_host,_port,timeout);
  if (_closed) {
    _socket.close();
    throw CONNECTION_CLOSED;
  }
  InetAddress localAddress=_socket.getLocalAddress();
  if (ConnectionSettings.LOCAL_IS_PRIVATE.getValue() && _socket.getInetAddress().equals(localAddress) && _port == ConnectionSettings.PORT.getValue()) {
    throw new IOException("String_Node_Str");
  }
  try {
    _in=getInputStream();
    _out=getOutputStream();
    if (_in == null)     throw new IOException("String_Node_Str");
 else     if (_out == null)     throw new IOException("String_Node_Str");
  }
 catch (  Exception e) {
    close();
    throw new IOException("String_Node_Str");
  }
  try {
    if (isOutgoing())     initializeOutgoing();
 else     initializeIncoming();
    _headers=HandshakeResponse.createResponse(HEADERS_READ);
    _headersWritten=HandshakeResponse.createResponse(HEADERS_WRITTEN);
    _connectionTime=System.currentTimeMillis();
    _softMax=ConnectionSettings.SOFT_MAX.getValue();
    if (isGoodUltrapeer() || isGoodLeaf()) {
      _softMax++;
    }
    if (isWriteDeflated()) {
      _deflater=new Deflater();
      _out=new CompressingOutputStream(_out,_deflater);
    }
    if (isReadDeflated()) {
      _inflater=new Inflater();
      _in=new UncompressingInputStream(_in,_inflater);
    }
    RESPONSE_HEADERS=null;
  }
 catch (  NoGnutellaOkException e) {
    close();
    throw e;
  }
catch (  IOException e) {
    close();
    throw new BadHandshakeException(e);
  }
}