Program: 103085
Project: 103085
Buggy source:
/** 
 * Connects and logins to the server
 * @param authority SecurityAuthority
 * @param reasonCode reason code in case of reconnect.
 * @throws OperationFailedException if login parametersas server port are not correct
 */
private void connectAndLogin(SecurityAuthority authority,int reasonCode) throws OperationFailedException {
synchronized (initializationLock) {
    ProtocolProviderFactoryIcqImpl protocolProviderFactory=null;
    if (USING_ICQ)     protocolProviderFactory=IcqActivator.getIcqProtocolProviderFactory();
 else     protocolProviderFactory=IcqActivator.getAimProtocolProviderFactory();
    String password=protocolProviderFactory.loadPassword(getAccountID());
    if (password == null) {
      UserCredentials credentials=new UserCredentials();
      credentials.setUserName(this.getAccountID().getUserID());
      credentials=authority.obtainCredentials(accountID.getDisplayName(),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(RegistrationState.UNREGISTERED,RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      password=new String(pass);
      if (credentials.isPasswordPersistent()) {
        protocolProviderFactory.storePassword(getAccountID(),password);
      }
    }
    if (USING_ICQ && password.length() > 8)     password=password.substring(0,8);
    session=new DefaultAppSession();
    aimSession=session.openAimSession(new Screenname(getAccountID().getUserID()));
    String globalProxyType=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTON_PROXY_TYPE_PROPERTY_NAME);
    if (globalProxyType != null && globalProxyType.equals(ProxyInfo.ProxyType.HTTP.name())) {
      String globalProxyAddress=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTON_PROXY_ADDRESS_PROPERTY_NAME);
      String globalProxyPortStr=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTON_PROXY_PORT_PROPERTY_NAME);
      int proxyPort;
      try {
        proxyPort=Integer.parseInt(globalProxyPortStr);
      }
 catch (      NumberFormatException ex) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES,ex);
      }
      String globalProxyUsername=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTON_PROXY_USERNAME_PROPERTY_NAME);
      String globalProxyPassword=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTON_PROXY_PASSWORD_PROPERTY_NAME);
      if (globalProxyAddress == null || globalProxyAddress.length() <= 0) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES);
      }
      AimConnectionProperties connProps=new AimConnectionProperties(new Screenname(getAccountID().getUserID()),password);
      if (USING_ICQ)       connProps.setLoginHost(ICQ_DEFAULT_LOGIN_SERVER);
 else       connProps.setLoginHost(AIM_DEFAULT_LOGIN_SERVER);
      connProps.setLoginPort(443);
      aimConnection=aimSession.openConnection(connProps);
      aimConnection.setProxy(AimProxyInfo.forHttp(globalProxyAddress,proxyPort,globalProxyUsername,globalProxyPassword));
    }
 else {
      AimConnectionProperties connProps=new AimConnectionProperties(new Screenname(getAccountID().getUserID()),password);
      if (USING_ICQ)       connProps.setLoginHost(ICQ_DEFAULT_LOGIN_SERVER);
 else       connProps.setLoginHost(AIM_DEFAULT_LOGIN_SERVER);
      aimConnection=aimSession.openConnection(connProps);
    }
    aimConnStateListener=new AimConnStateListener();
    aimConnection.addStateListener(aimConnStateListener);
    aimConnection.connect();
  }
}

Fixed version (ground truth):
/** 
 * Connects and logins to the server
 * @param authority SecurityAuthority
 * @param reasonCode reason code in case of reconnect.
 * @throws OperationFailedException if login parametersas server port are not correct
 */
private void connectAndLogin(SecurityAuthority authority,int reasonCode) throws OperationFailedException {
synchronized (initializationLock) {
    ProtocolProviderFactoryIcqImpl protocolProviderFactory=null;
    if (USING_ICQ)     protocolProviderFactory=IcqActivator.getIcqProtocolProviderFactory();
 else     protocolProviderFactory=IcqActivator.getAimProtocolProviderFactory();
    String password=protocolProviderFactory.loadPassword(getAccountID());
    if (password == null) {
      UserCredentials credentials=new UserCredentials();
      credentials.setUserName(this.getAccountID().getUserID());
      credentials=authority.obtainCredentials(accountID.getDisplayName(),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(RegistrationState.UNREGISTERED,RegistrationState.UNREGISTERED,RegistrationStateChangeEvent.REASON_USER_REQUEST,"String_Node_Str");
        return;
      }
      password=new String(pass);
      if (credentials.isPasswordPersistent()) {
        protocolProviderFactory.storePassword(getAccountID(),password);
      }
    }
    if (USING_ICQ && password.length() > 8)     password=password.substring(0,8);
    session=new DefaultAppSession();
    aimSession=session.openAimSession(new Screenname(getAccountID().getUserID()));
    String globalProxyType=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTION_PROXY_TYPE_PROPERTY_NAME);
    if (globalProxyType != null && globalProxyType.equals(ProxyInfo.ProxyType.HTTP.name())) {
      String globalProxyAddress=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTION_PROXY_ADDRESS_PROPERTY_NAME);
      String globalProxyPortStr=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTION_PROXY_PORT_PROPERTY_NAME);
      int proxyPort;
      try {
        proxyPort=Integer.parseInt(globalProxyPortStr);
      }
 catch (      NumberFormatException ex) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES,ex);
      }
      String globalProxyUsername=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTION_PROXY_USERNAME_PROPERTY_NAME);
      String globalProxyPassword=IcqActivator.getConfigurationService().getString(ProxyInfo.CONNECTION_PROXY_PASSWORD_PROPERTY_NAME);
      if (globalProxyAddress == null || globalProxyAddress.length() <= 0) {
        throw new OperationFailedException("String_Node_Str",OperationFailedException.INVALID_ACCOUNT_PROPERTIES);
      }
      AimConnectionProperties connProps=new AimConnectionProperties(new Screenname(getAccountID().getUserID()),password);
      if (USING_ICQ)       connProps.setLoginHost(ICQ_DEFAULT_LOGIN_SERVER);
 else       connProps.setLoginHost(AIM_DEFAULT_LOGIN_SERVER);
      connProps.setLoginPort(443);
      aimConnection=aimSession.openConnection(connProps);
      aimConnection.setProxy(AimProxyInfo.forHttp(globalProxyAddress,proxyPort,globalProxyUsername,globalProxyPassword));
    }
 else {
      AimConnectionProperties connProps=new AimConnectionProperties(new Screenname(getAccountID().getUserID()),password);
      if (USING_ICQ)       connProps.setLoginHost(ICQ_DEFAULT_LOGIN_SERVER);
 else       connProps.setLoginHost(AIM_DEFAULT_LOGIN_SERVER);
      aimConnection=aimSession.openConnection(connProps);
    }
    aimConnStateListener=new AimConnStateListener();
    aimConnection.addStateListener(aimConnStateListener);
    aimConnection.connect();
  }
}