Program: 103112
Project: 103112
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);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=loginStrategy.isTlsRequired();
  confConn.setSecurityMode(tlsRequired ? ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.enabled);
  if (connection != null) {
    logger.error("String_Node_Str" + connection.isConnected(),new Exception("String_Node_Str" + getAccountID().getAccountAddress()));
    disconnectAndCleanConnection();
  }
  connection=new XMPPConnection(confConn);
  try {
    CertificateService cvs=getCertificateVerificationService();
    if (cvs != null) {
      SSLContext sslContext=loginStrategy.createSslContext(cvs,getTrustManager(cvs,serviceName));
      connection.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");
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND,null);
    return ConnectState.ABORT_CONNECTING;
  }
 else {
    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();
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.CONNECTION_FAILED,RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED,loginStrategy.getClass().getName() + "String_Node_Str");
    return ConnectState.ABORT_CONNECTING;
  }
  if (connection.isAuthenticated()) {
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    OperationSetPersistentPresenceJabberImpl opSet=(OperationSetPersistentPresenceJabberImpl)this.getOperationSet(OperationSetPersistentPresence.class);
    try {
      opSet.publishPresenceStatus(getJabberStatusEnum().getStatus(JabberStatusEnum.AVAILABLE),"String_Node_Str");
    }
 catch (    Exception e) {
      logger.error("String_Node_Str");
    }
    return ConnectState.STOP_TRYING;
  }
 else {
    disconnectAndCleanConnection();
    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);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=loginStrategy.isTlsRequired();
  confConn.setSecurityMode(tlsRequired ? ConnectionConfiguration.SecurityMode.required : ConnectionConfiguration.SecurityMode.enabled);
  if (connection != null) {
    logger.error("String_Node_Str" + connection.isConnected(),new Exception("String_Node_Str" + getAccountID().getAccountAddress()));
    disconnectAndCleanConnection();
  }
  connection=new XMPPConnection(confConn);
  try {
    CertificateService cvs=getCertificateVerificationService();
    if (cvs != null) {
      SSLContext sslContext=loginStrategy.createSslContext(cvs,getTrustManager(cvs,serviceName));
      connection.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 {
    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);
    OperationSetPersistentPresenceJabberImpl opSet=(OperationSetPersistentPresenceJabberImpl)this.getOperationSet(OperationSetPersistentPresence.class);
    try {
      opSet.publishPresenceStatus(getJabberStatusEnum().getStatus(JabberStatusEnum.AVAILABLE),"String_Node_Str");
    }
 catch (    Exception e) {
      logger.error("String_Node_Str");
    }
    return ConnectState.STOP_TRYING;
  }
 else {
    disconnectAndCleanConnection();
    eventDuringLogin=null;
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.CONTINUE_TRYING;
  }
}