Program: 103345
Project: 103345
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 serverPort the port to use
 * @param serviceName the service name to use
 * @param userName the username to use
 * @param password the password to use
 * @param resource and the resource.
 * @return return the state how to continue the connect process.
 * @throws XMPPException if we cannot connect for some reason
 */
private ConnectState connectAndLogin(String address,int serverPort,String serviceName,String userName,String password,String resource) throws XMPPException {
  ConnectionConfiguration confConn=new ConnectionConfiguration(address,serverPort,serviceName,proxy);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=!accountID.getAccountPropertyBoolean(ProtocolProviderFactory.IS_ALLOW_NON_SECURE,false);
  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) {
      connection.setCustomTrustManager(new HostTrustManager(cvs.getTrustManager(Arrays.asList(new String[]{serviceName,"String_Node_Str" + serviceName}))));
    }
  }
 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();
  registerServiceDiscoveryManager();
  if (connectionListener == null) {
    connectionListener=new JabberConnectionListener();
  }
  if (!connection.isSecureConnection() && tlsRequired) {
    throw new XMPPException("String_Node_Str");
  }
  connection.addConnectionListener(connectionListener);
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
  SASLAuthentication.supportSASLMechanism("String_Node_Str",0);
  SASLAuthentication.unregisterSASLMechanism("String_Node_Str");
  SASLAuthentication.registerSASLMechanism("String_Node_Str",SASLDigestMD5Mechanism.class);
  SASLAuthentication.supportSASLMechanism("String_Node_Str");
  connection.login(userName,password,resource);
  if (connection.isAuthenticated()) {
    connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
    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");
    }
    startJingleNodesDiscovery();
    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 serverPort the port to use
 * @param serviceName the service name to use
 * @param userName the username to use
 * @param password the password to use
 * @param resource and the resource.
 * @return return the state how to continue the connect process.
 * @throws XMPPException if we cannot connect for some reason
 */
private ConnectState connectAndLogin(String address,int serverPort,String serviceName,String userName,String password,String resource) throws XMPPException {
  ConnectionConfiguration confConn=new ConnectionConfiguration(address,serverPort,serviceName,proxy);
  confConn.setReconnectionAllowed(false);
  boolean tlsRequired=!accountID.getAccountPropertyBoolean(ProtocolProviderFactory.IS_ALLOW_NON_SECURE,false);
  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) {
      connection.setCustomTrustManager(new HostTrustManager(cvs.getTrustManager(Arrays.asList(new String[]{serviceName,"String_Node_Str" + serviceName}))));
    }
  }
 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();
  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");
  }
  connection.addConnectionListener(connectionListener);
  if (abortConnecting) {
    abortConnecting=false;
    disconnectAndCleanConnection();
    return ConnectState.ABORT_CONNECTING;
  }
  fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
  SASLAuthentication.supportSASLMechanism("String_Node_Str",0);
  SASLAuthentication.unregisterSASLMechanism("String_Node_Str");
  SASLAuthentication.registerSASLMechanism("String_Node_Str",SASLDigestMD5Mechanism.class);
  SASLAuthentication.supportSASLMechanism("String_Node_Str");
  connection.login(userName,password,resource);
  if (connection.isAuthenticated()) {
    connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
    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");
    }
    startJingleNodesDiscovery();
    return ConnectState.STOP_TRYING;
  }
 else {
    disconnectAndCleanConnection();
    fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
    return ConnectState.CONTINUE_TRYING;
  }
}