Program: 103475
Project: 103475
Buggy source:
/** 
 * Creates an account for the given user and password.
 * @param providerFactory the ProtocolProviderFactory which will createthe account
 * @param userName the user identifier
 * @param passwd the password
 * @return the <tt>ProtocolProviderService</tt> for the new account.
 * @throws OperationFailedException problem installing account
 */
private ProtocolProviderService installAccount(ProtocolProviderFactory providerFactory,String userName,String passwd) throws OperationFailedException {
  HashMap<String,String> accountProperties=new HashMap<String,String>();
  accountProperties.put(ProtocolProviderFactory.PROTOCOL,getProtocol());
  String protocolIconPath=getProtocolIconPath();
  if (protocolIconPath != null)   accountProperties.put(ProtocolProviderFactory.PROTOCOL_ICON_PATH,protocolIconPath);
  String accountIconPath=getAccountIconPath();
  if (accountIconPath != null)   accountProperties.put(ProtocolProviderFactory.ACCOUNT_ICON_PATH,accountIconPath);
  if (registration.isRememberPassword()) {
    accountProperties.put(ProtocolProviderFactory.PASSWORD,passwd);
  }
  String serverAddress=null;
  String serverFromUsername=SIPAccountRegistrationForm.getServerFromUserName(userName);
  if (registration.getServerAddress() != null)   serverAddress=registration.getServerAddress();
  if (serverFromUsername == null && registration.getDefaultDomain() != null) {
    userName=userName + "String_Node_Str" + registration.getDefaultDomain();
    if (serverAddress == null)     serverAddress=registration.getDefaultDomain();
  }
 else   if (serverAddress == null && serverFromUsername != null) {
    serverAddress=serverFromUsername;
  }
  if (serverAddress != null) {
    accountProperties.put(ProtocolProviderFactory.SERVER_ADDRESS,serverAddress);
    if (userName.indexOf(serverAddress) < 0)     accountProperties.put(ProtocolProviderFactory.IS_SERVER_OVERRIDDEN,Boolean.toString(true));
  }
  accountProperties.put(ProtocolProviderFactory.DISPLAY_NAME,registration.getDisplayName());
  accountProperties.put(ProtocolProviderFactory.AUTHORIZATION_NAME,registration.getAuthorizationName());
  accountProperties.put(ProtocolProviderFactory.SERVER_PORT,registration.getServerPort());
  if (registration.isProxyAutoConfigure()) {
    accountProperties.put(ProtocolProviderFactory.PROXY_AUTO_CONFIG,Boolean.TRUE.toString());
  }
 else {
    accountProperties.put(ProtocolProviderFactory.PROXY_ADDRESS,registration.getProxy());
    accountProperties.put(ProtocolProviderFactory.PROXY_PORT,registration.getProxyPort());
    accountProperties.put(ProtocolProviderFactory.PREFERRED_TRANSPORT,registration.getPreferredTransport());
  }
  accountProperties.put(ProtocolProviderFactory.IS_PRESENCE_ENABLED,Boolean.toString(registration.isEnablePresence()));
  if (serverAddress != null) {
    accountProperties.put(ProtocolProviderFactory.FORCE_P2P_MODE,Boolean.toString(registration.isForceP2PMode()));
  }
 else {
    accountProperties.put(ProtocolProviderFactory.FORCE_P2P_MODE,Boolean.TRUE.toString());
  }
  accountProperties.put(ProtocolProviderFactory.DEFAULT_ENCRYPTION,Boolean.toString(registration.isDefaultEncryption()));
  accountProperties.put(ProtocolProviderFactory.DEFAULT_SIPZRTP_ATTRIBUTE,Boolean.toString(registration.isSipZrtpAttribute()));
  accountProperties.put(ProtocolProviderFactory.POLLING_PERIOD,registration.getPollingPeriod());
  accountProperties.put(ProtocolProviderFactory.SUBSCRIPTION_EXPIRATION,registration.getSubscriptionExpiration());
  if (registration.getKeepAliveMethod() != null)   accountProperties.put("String_Node_Str",registration.getKeepAliveMethod());
 else   accountProperties.put("String_Node_Str",registration.getDefaultKeepAliveMethod());
  accountProperties.put("String_Node_Str",registration.getKeepAliveInterval());
  accountProperties.put("String_Node_Str",Boolean.toString(registration.isXCapEnable()));
  if (registration.isXCapEnable()) {
    accountProperties.put("String_Node_Str",Boolean.toString(registration.isXCapUseSipCredetials()));
    if (registration.getXCapServerUri() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapServerUri());
    }
    if (registration.getXCapUser() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapUser());
    }
    if (registration.getXCapPassword() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapPassword());
    }
  }
  if (!StringUtils.isNullOrEmpty(registration.getVoicemailURI(),true))   accountProperties.put(ProtocolProviderFactory.VOICEMAIL_URI,registration.getVoicemailURI());
  if (isModification) {
    accountProperties.put(ProtocolProviderFactory.USER_ID,userName);
    providerFactory.modifyAccount(protocolProvider,accountProperties);
    this.isModification=false;
    return protocolProvider;
  }
  try {
    AccountID accountID=providerFactory.installAccount(userName,accountProperties);
    ServiceReference serRef=providerFactory.getProviderForAccount(accountID);
    protocolProvider=(ProtocolProviderService)SIPAccRegWizzActivator.bundleContext.getService(serRef);
  }
 catch (  IllegalStateException exc) {
    logger.warn(exc.getMessage());
    throw new OperationFailedException("String_Node_Str",OperationFailedException.IDENTIFICATION_CONFLICT);
  }
catch (  Exception exc) {
    logger.warn(exc.getMessage());
    throw new OperationFailedException(exc.getMessage(),OperationFailedException.GENERAL_ERROR);
  }
  return protocolProvider;
}

Fixed version (ground truth):
/** 
 * Creates an account for the given user and password.
 * @param providerFactory the ProtocolProviderFactory which will createthe account
 * @param userName the user identifier
 * @param passwd the password
 * @return the <tt>ProtocolProviderService</tt> for the new account.
 * @throws OperationFailedException problem installing account
 */
private ProtocolProviderService installAccount(ProtocolProviderFactory providerFactory,String userName,String passwd) throws OperationFailedException {
  HashMap<String,String> accountProperties=new HashMap<String,String>();
  accountProperties.put(ProtocolProviderFactory.PROTOCOL,getProtocol());
  String protocolIconPath=getProtocolIconPath();
  if (protocolIconPath != null)   accountProperties.put(ProtocolProviderFactory.PROTOCOL_ICON_PATH,protocolIconPath);
  String accountIconPath=getAccountIconPath();
  if (accountIconPath != null)   accountProperties.put(ProtocolProviderFactory.ACCOUNT_ICON_PATH,accountIconPath);
  if (registration.isRememberPassword()) {
    accountProperties.put(ProtocolProviderFactory.PASSWORD,passwd);
  }
  String serverAddress=null;
  String serverFromUsername=SIPAccountRegistrationForm.getServerFromUserName(userName);
  if (registration.getServerAddress() != null)   serverAddress=registration.getServerAddress();
  if (serverFromUsername == null && registration.getDefaultDomain() != null) {
    userName=userName + "String_Node_Str" + registration.getDefaultDomain();
    if (serverAddress == null)     serverAddress=registration.getDefaultDomain();
  }
 else   if (serverAddress == null && serverFromUsername != null) {
    serverAddress=serverFromUsername;
  }
  if (serverAddress != null) {
    accountProperties.put(ProtocolProviderFactory.SERVER_ADDRESS,serverAddress);
    if (userName.indexOf(serverAddress) < 0)     accountProperties.put(ProtocolProviderFactory.IS_SERVER_OVERRIDDEN,Boolean.toString(true));
  }
  accountProperties.put(ProtocolProviderFactory.DISPLAY_NAME,registration.getDisplayName());
  accountProperties.put(ProtocolProviderFactory.AUTHORIZATION_NAME,registration.getAuthorizationName());
  accountProperties.put(ProtocolProviderFactory.SERVER_PORT,registration.getServerPort());
  if (registration.isProxyAutoConfigure()) {
    accountProperties.put(ProtocolProviderFactory.PROXY_AUTO_CONFIG,Boolean.TRUE.toString());
  }
 else {
    accountProperties.put(ProtocolProviderFactory.PROXY_AUTO_CONFIG,Boolean.FALSE.toString());
    accountProperties.put(ProtocolProviderFactory.PROXY_ADDRESS,registration.getProxy());
    accountProperties.put(ProtocolProviderFactory.PROXY_PORT,registration.getProxyPort());
    accountProperties.put(ProtocolProviderFactory.PREFERRED_TRANSPORT,registration.getPreferredTransport());
  }
  accountProperties.put(ProtocolProviderFactory.IS_PRESENCE_ENABLED,Boolean.toString(registration.isEnablePresence()));
  if (serverAddress != null) {
    accountProperties.put(ProtocolProviderFactory.FORCE_P2P_MODE,Boolean.toString(registration.isForceP2PMode()));
  }
 else {
    accountProperties.put(ProtocolProviderFactory.FORCE_P2P_MODE,Boolean.TRUE.toString());
  }
  accountProperties.put(ProtocolProviderFactory.DEFAULT_ENCRYPTION,Boolean.toString(registration.isDefaultEncryption()));
  accountProperties.put(ProtocolProviderFactory.DEFAULT_SIPZRTP_ATTRIBUTE,Boolean.toString(registration.isSipZrtpAttribute()));
  accountProperties.put(ProtocolProviderFactory.POLLING_PERIOD,registration.getPollingPeriod());
  accountProperties.put(ProtocolProviderFactory.SUBSCRIPTION_EXPIRATION,registration.getSubscriptionExpiration());
  if (registration.getKeepAliveMethod() != null)   accountProperties.put("String_Node_Str",registration.getKeepAliveMethod());
 else   accountProperties.put("String_Node_Str",registration.getDefaultKeepAliveMethod());
  accountProperties.put("String_Node_Str",registration.getKeepAliveInterval());
  accountProperties.put("String_Node_Str",Boolean.toString(registration.isXCapEnable()));
  if (registration.isXCapEnable()) {
    accountProperties.put("String_Node_Str",Boolean.toString(registration.isXCapUseSipCredetials()));
    if (registration.getXCapServerUri() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapServerUri());
    }
    if (registration.getXCapUser() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapUser());
    }
    if (registration.getXCapPassword() != null) {
      accountProperties.put("String_Node_Str",registration.getXCapPassword());
    }
  }
  if (!StringUtils.isNullOrEmpty(registration.getVoicemailURI(),true))   accountProperties.put(ProtocolProviderFactory.VOICEMAIL_URI,registration.getVoicemailURI());
  if (isModification) {
    accountProperties.put(ProtocolProviderFactory.USER_ID,userName);
    providerFactory.modifyAccount(protocolProvider,accountProperties);
    this.isModification=false;
    return protocolProvider;
  }
  try {
    AccountID accountID=providerFactory.installAccount(userName,accountProperties);
    ServiceReference serRef=providerFactory.getProviderForAccount(accountID);
    protocolProvider=(ProtocolProviderService)SIPAccRegWizzActivator.bundleContext.getService(serRef);
  }
 catch (  IllegalStateException exc) {
    logger.warn(exc.getMessage());
    throw new OperationFailedException("String_Node_Str",OperationFailedException.IDENTIFICATION_CONFLICT);
  }
catch (  Exception exc) {
    logger.warn(exc.getMessage());
    throw new OperationFailedException(exc.getMessage(),OperationFailedException.GENERAL_ERROR);
  }
  return protocolProvider;
}