Program: 104081
Project: 104081
Buggy source:
/** 
 * Connects and logins to the server
 * @param authority SecurityAuthority
 * @param reasonCode the authentication reason code. Indicates the reason ofthis authentication.
 * @throws XMPPException if we cannot connect to the server - network problem
 * @throws OperationFailedException if login parametersas server port are not correct
 */
private void connectAndLogin(SecurityAuthority authority,int reasonCode) throws XMPPException, OperationFailedException {
synchronized (initializationLock) {
    String password=JabberActivator.getProtocolProviderFactory().loadPassword(getAccountID());
    if (password == null) {
      UserCredentials credentials=new UserCredentials();
      credentials.setUserName(getAccountID().getUserID());
      credentials=authority.obtainCredentials(ProtocolNames.JABBER,credentials,reasonCode);
      if (credentials == null) {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      char[] pass=credentials.getPassword();
      if (pass == null) {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      password=new String(pass);
      if (credentials.isPasswordPersistent()) {
        JabberActivator.getProtocolProviderFactory().storePassword(getAccountID(),password);
      }
    }
    try {
      String userID=StringUtils.parseName(getAccountID().getUserID());
      String serviceName=StringUtils.parseServer(getAccountID().getUserID());
      String serverAddress=getAccountID().getAccountPropertyString(ProtocolProviderFactory.SERVER_ADDRESS);
      String serverPort=getAccountID().getAccountPropertyString(ProtocolProviderFactory.SERVER_PORT);
      String accountResource=getAccountID().getAccountPropertyString(ProtocolProviderFactory.RESOURCE);
      try {
        InetSocketAddress srvAddress=NetworkUtils.getSRVRecord("String_Node_Str","String_Node_Str",serviceName);
        if (srvAddress != null)         serverAddress=srvAddress.getHostName();
      }
 catch (      ParseException ex1) {
        logger.error("String_Node_Str" + ex1.getMessage());
      }
      Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
      try {
        ConnectionConfiguration confConn=new ConnectionConfiguration(serverAddress,Integer.parseInt(serverPort),serviceName);
        confConn.setReconnectionAllowed(false);
        connection=new XMPPConnection(confConn);
        connection.connect();
      }
 catch (      XMPPException exc) {
        logger.error("String_Node_Str" + getAccountID().getAccountUniqueID(),exc);
        throw new OperationFailedException("String_Node_Str" + getAccountID().getAccountUniqueID(),OperationFailedException.NETWORK_FAILURE,exc);
      }
      connection.addConnectionListener(new JabberConnectionListener());
      fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      if (accountResource == null || accountResource.equals("String_Node_Str"))       accountResource="String_Node_Str";
      SASLAuthentication.supportSASLMechanism("String_Node_Str",0);
      try {
        connection.login(userID,password,accountResource);
      }
 catch (      XMPPException e1) {
        try {
          try {
            connection.disconnect();
          }
 catch (          Exception e) {
          }
          connection.connect();
          connection.login(userID + "String_Node_Str" + serviceName,password,accountResource);
        }
 catch (        XMPPException e2) {
          throw e1;
        }
      }
      if (connection.isAuthenticated()) {
        this.reconnecting=false;
        connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      }
 else {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      }
    }
 catch (    NumberFormatException ex) {
      throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES,ex);
    }
  }
  if (getRegistrationState() == RegistrationState.REGISTERED) {
    discoveryManager=ServiceDiscoveryManager.getInstanceFor(connection);
    ServiceDiscoveryManager.setIdentityName("String_Node_Str");
    ServiceDiscoveryManager.setIdentityType("String_Node_Str");
    Iterator<String> it=supportedFeatures.iterator();
    while (it.hasNext())     discoveryManager.addFeature(it.next());
  }
}

Fixed version (ground truth):
/** 
 * Connects and logins to the server
 * @param authority SecurityAuthority
 * @param reasonCode the authentication reason code. Indicates the reason ofthis authentication.
 * @throws XMPPException if we cannot connect to the server - network problem
 * @throws OperationFailedException if login parametersas server port are not correct
 */
private synchronized void connectAndLogin(SecurityAuthority authority,int reasonCode) throws XMPPException, OperationFailedException {
synchronized (initializationLock) {
    String password=JabberActivator.getProtocolProviderFactory().loadPassword(getAccountID());
    if (password == null) {
      UserCredentials credentials=new UserCredentials();
      credentials.setUserName(getAccountID().getUserID());
      credentials=authority.obtainCredentials(ProtocolNames.JABBER,credentials,reasonCode);
      if (credentials == null) {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      char[] pass=credentials.getPassword();
      if (pass == null) {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      password=new String(pass);
      if (credentials.isPasswordPersistent()) {
        JabberActivator.getProtocolProviderFactory().storePassword(getAccountID(),password);
      }
    }
    try {
      String userID=StringUtils.parseName(getAccountID().getUserID());
      String serviceName=StringUtils.parseServer(getAccountID().getUserID());
      String serverAddress=getAccountID().getAccountPropertyString(ProtocolProviderFactory.SERVER_ADDRESS);
      String serverPort=getAccountID().getAccountPropertyString(ProtocolProviderFactory.SERVER_PORT);
      String accountResource=getAccountID().getAccountPropertyString(ProtocolProviderFactory.RESOURCE);
      try {
        InetSocketAddress srvAddress=NetworkUtils.getSRVRecord("String_Node_Str","String_Node_Str",serviceName);
        if (srvAddress != null)         serverAddress=srvAddress.getHostName();
      }
 catch (      ParseException ex1) {
        logger.error("String_Node_Str" + ex1.getMessage());
      }
      Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
      try {
        ConnectionConfiguration confConn=new ConnectionConfiguration(serverAddress,Integer.parseInt(serverPort),serviceName);
        confConn.setReconnectionAllowed(false);
        connection=new XMPPConnection(confConn);
        connection.connect();
      }
 catch (      XMPPException exc) {
        logger.error("String_Node_Str" + getAccountID().getAccountUniqueID(),exc);
        throw new OperationFailedException("String_Node_Str" + getAccountID().getAccountUniqueID(),OperationFailedException.NETWORK_FAILURE,exc);
      }
      connection.addConnectionListener(new JabberConnectionListener());
      fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERING,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      if (accountResource == null || accountResource.equals("String_Node_Str"))       accountResource="String_Node_Str";
      SASLAuthentication.supportSASLMechanism("String_Node_Str",0);
      try {
        connection.login(userID,password,accountResource);
      }
 catch (      XMPPException e1) {
        try {
          try {
            connection.disconnect();
          }
 catch (          Exception e) {
          }
          connection.connect();
          connection.login(userID + "String_Node_Str" + serviceName,password,accountResource);
        }
 catch (        XMPPException e2) {
          throw e1;
        }
      }
      if (connection.isAuthenticated()) {
        this.reconnecting=false;
        connection.getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.REGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      }
 else {
        fireRegistrationStateChanged(getRegistrationState(),RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_NOT_SPECIFIED,null);
      }
    }
 catch (    NumberFormatException ex) {
      throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES,ex);
    }
  }
  if (getRegistrationState() == RegistrationState.REGISTERED) {
    discoveryManager=ServiceDiscoveryManager.getInstanceFor(connection);
    ServiceDiscoveryManager.setIdentityName("String_Node_Str");
    ServiceDiscoveryManager.setIdentityType("String_Node_Str");
    Iterator<String> it=supportedFeatures.iterator();
    while (it.hasNext())     discoveryManager.addFeature(it.next());
  }
}