Program: 4626
Project: 4626
Buggy source:
/** 
 * Responds to the handshake from the host on the other end of the connection, till a conclusion reaches. Handshaking may involve multiple steps.
 * @exception NoGnutellaOkException one of the participants respondedwith an error code other than 200 OK (possibly after several rounds of 401's)
 * @exception IOException any other error.  May wish to retry at 0.4
 */
private void concludeIncomingHandshake() throws IOException {
  for (int i=0; i < MAX_HANDSHAKE_ATTEMPTS; i++) {
    boolean isCrawler=_headers.isCrawler();
    HandshakeResponse ourResponse=RESPONSE_HEADERS.respond(_headers,false);
    writeLine(GNUTELLA_06 + "String_Node_Str" + ourResponse.getStatusLine()+ CRLF);
    sendHeaders(ourResponse.props());
    int code=ourResponse.getStatusCode();
    if ((code != HandshakeResponse.OK) && (code != HandshakeResponse.UNAUTHORIZED_CODE)) {
      if (code == HandshakeResponse.SLOTS_FULL) {
        throw NoGnutellaOkException.CLIENT_REJECT;
      }
 else {
        throw NoGnutellaOkException.createClientUnknown(code);
      }
    }
    String connectLine;
    if (ourResponse.getStatusCode() == HandshakeResponse.UNAUTHORIZED_CODE) {
      connectLine=readLine(USER_INPUT_WAIT_TIME);
      readHeaders(USER_INPUT_WAIT_TIME);
      _headers=HandshakeResponse.createResponse(HEADERS_READ);
    }
 else {
      connectLine=readLine();
      readHeaders();
    }
    if (!connectLine.startsWith(GNUTELLA_06))     throw new IOException("String_Node_Str");
    HandshakeResponse theirResponse=HandshakeResponse.createResponse(connectLine.substring(GNUTELLA_06.length()).trim(),HEADERS_READ);
    code=ourResponse.getStatusCode();
    if (code == HandshakeResponse.OK && theirResponse.getStatusCode() == HandshakeResponse.OK) {
      if (isCrawler) {
        throw new IOException("String_Node_Str");
      }
      return;
    }
 else {
      Assert.that(code == HandshakeResponse.UNAUTHORIZED_CODE,"String_Node_Str" + code);
      if (theirResponse.getStatusCode() == HandshakeResponse.OK)       continue;
    }
    throw NoGnutellaOkException.createServerUnknown(theirResponse.getStatusCode());
  }
  throw NoGnutellaOkException.UNRESOLVED_CLIENT;
}

Fixed version (ground truth):
/** 
 * Responds to the handshake from the host on the other end of the connection, till a conclusion reaches. Handshaking may involve multiple steps.
 * @exception NoGnutellaOkException one of the participants respondedwith an error code other than 200 OK (possibly after several rounds of 401's)
 * @exception IOException any other error.  May wish to retry at 0.4
 */
private void concludeIncomingHandshake() throws IOException {
  for (int i=0; i < MAX_HANDSHAKE_ATTEMPTS; i++) {
    boolean isCrawler=_headers.isCrawler();
    HandshakeResponse ourResponse=RESPONSE_HEADERS.respond(_headers,false);
    writeLine(GNUTELLA_06 + "String_Node_Str" + ourResponse.getStatusLine()+ CRLF);
    sendHeaders(ourResponse.props());
    int code=ourResponse.getStatusCode();
    if ((code != HandshakeResponse.OK) && (code != HandshakeResponse.UNAUTHORIZED_CODE)) {
      if (code == HandshakeResponse.SLOTS_FULL) {
        throw NoGnutellaOkException.CLIENT_REJECT;
      }
 else {
        throw NoGnutellaOkException.createClientUnknown(code);
      }
    }
    String connectLine;
    if (ourResponse.getStatusCode() == HandshakeResponse.UNAUTHORIZED_CODE) {
      connectLine=readLine(USER_INPUT_WAIT_TIME);
      readHeaders(USER_INPUT_WAIT_TIME);
      _headers=HandshakeResponse.createResponse(HEADERS_READ);
    }
 else {
      connectLine=readLine();
      readHeaders();
    }
    if (!connectLine.startsWith(GNUTELLA_06))     throw new IOException("String_Node_Str");
    HandshakeResponse theirResponse=HandshakeResponse.createResponse(connectLine.substring(GNUTELLA_06.length()).trim(),HEADERS_READ);
    code=ourResponse.getStatusCode();
    if (code == HandshakeResponse.OK) {
      if (theirResponse.getStatusCode() == HandshakeResponse.OK) {
        if (isCrawler) {
          throw new IOException("String_Node_Str");
        }
        return;
      }
    }
 else {
      Assert.that(code == HandshakeResponse.UNAUTHORIZED_CODE,"String_Node_Str" + code);
      if (theirResponse.getStatusCode() == HandshakeResponse.OK)       continue;
    }
    throw NoGnutellaOkException.createServerUnknown(theirResponse.getStatusCode());
  }
  throw NoGnutellaOkException.UNRESOLVED_CLIENT;
}