Program: 103771
Project: 103771
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 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) {
        if (logger.isInfoEnabled()) {
          logger.info("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);
      SASLAuthentication.unregisterSASLMechanism("String_Node_Str");
      SASLAuthentication.registerSASLMechanism("String_Node_Str",SASLDigestMD5Mechanism.class);
      SASLAuthentication.supportSASLMechanism("String_Node_Str");
      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();
    discoveryManager.removeFeature("String_Node_Str");
    while (it.hasNext()) {
      String feature=it.next();
      if (!discoveryManager.includesFeature(feature))       discoveryManager.addFeature(feature);
    }
  }
}

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) {
        if (logger.isInfoEnabled()) {
          logger.info("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);
      SASLAuthentication.unregisterSASLMechanism("String_Node_Str");
      SASLAuthentication.registerSASLMechanism("String_Node_Str",SASLDigestMD5Mechanism.class);
      SASLAuthentication.supportSASLMechanism("String_Node_Str");
      try {
        connection.login(userID,password,accountResource);
      }
 catch (      XMPPException e1) {
        try {
          try {
            connection.disconnect();
          }
 catch (          Exception e) {
          }
          connection.connect();
          connection.addConnectionListener(new JabberConnectionListener());
          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();
    discoveryManager.removeFeature("String_Node_Str");
    while (it.hasNext()) {
      String feature=it.next();
      if (!discoveryManager.includesFeature(feature))       discoveryManager.addFeature(feature);
    }
  }
}