Program: 102922
Project: 102922
Buggy source:
/** 
 * Connects xmpp connection and login. Returning the state whether is it final - Abort due to certificate cancel or keep trying cause only current address has failed or stop trying cause we succeeded.
 * @param address the address to connect to
 * @param serviceName the service name to use
 * @param userName the username to use
 * @param resource and the resource.
 * @param loginStrategy the login strategy to use
 * @return return the state how to continue the connect process.
 * @throws XMPPException if we cannot connect for some reason
 */
private ConnectState connectAndLogin(InetSocketAddress address,String serviceName,String userName,String resource,JabberLoginStrategy loginStrategy) throws XMPPException {
  ConnectionConfiguration confConn=new ConnectionConfiguration(address.getAddress().getHostAddress(),address.getPort(),serviceName,proxy);
  if (getOperationSet(OperationSetPersistentPresence.class) != null)   confConn.setSendPresence(false);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=loginStrategy.isTlsRequired();
  confConn.setSecurityMode(tlsRequired ? ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.enabled);
  TLSUtils.setTLSOnly(confConn);
  if (connection != null) {
    logger.error("String_Node_Str" + connection.isConnected(),new Exception("String_Node_Str" + getAccountID().getAccountAddress()));
    disconnectAndCleanConnection();
  }
  connection=new XMPPConnection(confConn);
  this.address=address;
  try {
    CertificateService cvs=getCertificateVerificationService();
    if (cvs != null) {
      SSLContext sslContext=loginStrategy.createSslContext(cvs,getTrustManager(cvs,serviceName));
      if (logger.isDebugEnabled()) {
        final StringBuilder buff=new StringBuilder();
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getDefaultSSLParameters().getProtocols()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getSupportedSSLParameters().getProtocols()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getDefaultSSLParameters().getCipherSuites()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getSupportedSSLParameters().getCipherSuites()));
        logger.debug(buff.toString());
      }
      confConn.setCustomSSLContext(sslContext);
    }
 else     if (tlsRequired)     throw new XMPPException("String_Node_Str" + "String_Node_Str");
  }
 catch (  GeneralSecurityException e) {
    logger.error("String_Node_Str",e);
    throw new XMPPException("String_Node_Str",e);
  }
  if (debugger == null)   debugger=new SmackPacketDebugger();
  debugger.setConnection(connection);
  connection.addPacketListener(debugger,null);
  connection.addPacketInterceptor(debugger,null);
  connection.connect();
  setTrafficClass();
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  registerServiceDiscoveryManager();
  if (connectionListener == null) {
    connectionListener=new JabberConnectionListener();
  }
  if (!connection.isSecureConnection() && tlsRequired) {
    throw new XMPPException("String_Node_Str");
  }
  if (!connection.isConnected()) {
    disconnectAndCleanConnection();
    logger.error("String_Node_Str");
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND,null);
    return ConnectState.ABORT_CONNECTING;
  }
 else {
    if (connection.getSocket() instanceof SSLSocket) {
      final SSLSocket sslSocket=(SSLSocket)connection.getSocket();
      StringBuilder buff=new StringBuilder();
      buff.append("String_Node_Str").append("String_Node_Str").append(sslSocket.getSession().getProtocol()).append("String_Node_Str").append("String_Node_Str").append(sslSocket.getSession().getCipherSuite());
      logger.info(buff.toString());
      if (logger.isDebugEnabled()) {
        buff=new StringBuilder();
        buff.append("String_Node_Str");
        try {
          buff.append(Arrays.toString(sslSocket.getSession().getPeerCertificates()));
        }
 catch (        SSLPeerUnverifiedException ex) {
          buff.append("String_Node_Str").append(ex.getLocalizedMessage()).append("String_Node_Str");
        }
        logger.debug(buff.toString());
      }
    }
    connection.addConnectionListener(connectionListener);
  }
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
  if (!loginStrategy.login(connection,userName,resource)) {
    disconnectAndCleanConnection();
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED,loginStrategy.getClass().getName() + "String_Node_Str");
    return ConnectState.ABORT_CONNECTING;
  }
  if (connection.isAuthenticated()) {
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.STOP_TRYING;
  }
 else {
    disconnectAndCleanConnection();
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.CONTINUE_TRYING;
  }
}

Fixed version (ground truth):
/** 
 * Connects xmpp connection and login. Returning the state whether is it final - Abort due to certificate cancel or keep trying cause only current address has failed or stop trying cause we succeeded.
 * @param address the address to connect to
 * @param serviceName the service name to use
 * @param userName the username to use
 * @param resource and the resource.
 * @param loginStrategy the login strategy to use
 * @return return the state how to continue the connect process.
 * @throws XMPPException if we cannot connect for some reason
 */
private ConnectState connectAndLogin(InetSocketAddress address,String serviceName,String userName,String resource,JabberLoginStrategy loginStrategy) throws XMPPException {
  ConnectionConfiguration confConn=new ConnectionConfiguration(address.getAddress().getHostAddress(),address.getPort(),serviceName,proxy);
  if (getOperationSet(OperationSetPersistentPresence.class) != null)   confConn.setSendPresence(false);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=loginStrategy.isTlsRequired();
  confConn.setSecurityMode(tlsRequired ? ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.enabled);
  TLSUtils.setTLSOnly(confConn);
  if (connection != null) {
    logger.error("String_Node_Str" + connection.isConnected(),new Exception("String_Node_Str" + getAccountID().getAccountAddress()));
    disconnectAndCleanConnection();
  }
  connection=new XMPPConnection(confConn);
  this.address=address;
  try {
    CertificateService cvs=getCertificateVerificationService();
    if (cvs != null) {
      SSLContext sslContext=loginStrategy.createSslContext(cvs,getTrustManager(cvs,serviceName));
      if (logger.isDebugEnabled() && sslContext != null) {
        final StringBuilder buff=new StringBuilder();
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getDefaultSSLParameters().getProtocols()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getSupportedSSLParameters().getProtocols()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getDefaultSSLParameters().getCipherSuites()));
        buff.append("String_Node_Str");
        buff.append("String_Node_Str");
        buff.append(Arrays.toString(sslContext.getSupportedSSLParameters().getCipherSuites()));
        logger.debug(buff.toString());
      }
      confConn.setCustomSSLContext(sslContext);
    }
 else     if (tlsRequired)     throw new XMPPException("String_Node_Str" + "String_Node_Str");
  }
 catch (  GeneralSecurityException e) {
    logger.error("String_Node_Str",e);
    throw new XMPPException("String_Node_Str",e);
  }
  if (debugger == null)   debugger=new SmackPacketDebugger();
  debugger.setConnection(connection);
  connection.addPacketListener(debugger,null);
  connection.addPacketInterceptor(debugger,null);
  connection.connect();
  setTrafficClass();
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  registerServiceDiscoveryManager();
  if (connectionListener == null) {
    connectionListener=new JabberConnectionListener();
  }
  if (!connection.isSecureConnection() && tlsRequired) {
    throw new XMPPException("String_Node_Str");
  }
  if (!connection.isConnected()) {
    disconnectAndCleanConnection();
    logger.error("String_Node_Str");
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND,null);
    return ConnectState.ABORT_CONNECTING;
  }
 else {
    if (connection.getSocket() instanceof SSLSocket) {
      final SSLSocket sslSocket=(SSLSocket)connection.getSocket();
      StringBuilder buff=new StringBuilder();
      buff.append("String_Node_Str").append("String_Node_Str").append(sslSocket.getSession().getProtocol()).append("String_Node_Str").append("String_Node_Str").append(sslSocket.getSession().getCipherSuite());
      logger.info(buff.toString());
      if (logger.isDebugEnabled()) {
        buff=new StringBuilder();
        buff.append("String_Node_Str");
        try {
          buff.append(Arrays.toString(sslSocket.getSession().getPeerCertificates()));
        }
 catch (        SSLPeerUnverifiedException ex) {
          buff.append("String_Node_Str").append(ex.getLocalizedMessage()).append("String_Node_Str");
        }
        logger.debug(buff.toString());
      }
    }
    connection.addConnectionListener(connectionListener);
  }
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
  if (!loginStrategy.login(connection,userName,resource)) {
    disconnectAndCleanConnection();
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED,loginStrategy.getClass().getName() + "String_Node_Str");
    return ConnectState.ABORT_CONNECTING;
  }
  if (connection.isAuthenticated()) {
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.STOP_TRYING;
  }
 else {
    disconnectAndCleanConnection();
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.CONTINUE_TRYING;
  }
}