Program: 105194
Project: 105194
Buggy source:
@Override public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd){
  final NuageVspResource resource=new NuageVspResource();
  final String deviceName=Network.Provider.NuageVsp.getName();
  ExternalNetworkDeviceManager.NetworkDevice networkDevice=ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
  final Long physicalNetworkId=cmd.getPhysicalNetworkId();
  PhysicalNetworkVO physicalNetwork=_physicalNetworkDao.findById(physicalNetworkId);
  if (physicalNetwork == null) {
    throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
  }
  long zoneId=physicalNetwork.getDataCenterId();
  final PhysicalNetworkServiceProviderVO ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),networkDevice.getNetworkServiceProvder());
  if (ntwkSvcProvider == null) {
    throw new CloudRuntimeException("String_Node_Str" + networkDevice.getNetworkServiceProvder() + "String_Node_Str"+ physicalNetworkId+ "String_Node_Str");
  }
 else   if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
    throw new CloudRuntimeException("String_Node_Str" + ntwkSvcProvider.getProviderName() + "String_Node_Str"+ physicalNetworkId+ "String_Node_Str");
  }
  if (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  try {
    NuageVspPluginClientLoader clientLoader=NuageVspPluginClientLoader.getClientLoader(null,null,1,1,null);
    Map<String,Object> clientDefaults=clientLoader.getNuageVspManagerClient().getClientDefaults();
    String apiVersion=MoreObjects.firstNonNull(cmd.getApiVersion(),(String)clientDefaults.get("String_Node_Str"));
    if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
      throw new CloudRuntimeException("String_Node_Str" + apiVersion);
    }
    int port=cmd.getPort();
    if (0 == port) {
      port=8443;
    }
    String cmsUserPasswordBase64=org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes()));
    String retryCount=String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(),clientDefaults.get("String_Node_Str")));
    String retryInterval=String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(),clientDefaults.get("String_Node_Str")));
    NuageVspResource.Configuration resourceConfiguration=new NuageVspResource.Configuration().name("String_Node_Str" + cmd.getHostName()).guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(apiVersion).apiRelativePath("String_Node_Str" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
    Map<String,String> hostDetails=resourceConfiguration.build();
    resource.configure(cmd.getHostName(),Maps.<String,Object>newHashMap(hostDetails));
    Host host=_resourceMgr.addHost(zoneId,resource,Host.Type.L2Networking,hostDetails);
    if (host == null) {
      throw new CloudRuntimeException("String_Node_Str");
    }
    NuageVspDeviceVO nuageVspDevice=new NuageVspDeviceVO(host.getId(),physicalNetworkId,ntwkSvcProvider.getProviderName(),deviceName);
    _nuageVspDao.persist(nuageVspDevice);
    DetailVO detail=new DetailVO(host.getId(),"String_Node_Str",String.valueOf(nuageVspDevice.getId()));
    _hostDetailsDao.persist(detail);
    ConfigurationVO cmsIdConfig=_configDao.findByName("String_Node_Str");
    host=findNuageVspHost(nuageVspDevice.getHostId());
    SyncNuageVspCmsIdCommand syncCmd=new SyncNuageVspCmsIdCommand(SyncType.REGISTER,null);
    SyncNuageVspCmsIdAnswer answer=(SyncNuageVspCmsIdAnswer)_agentMgr.easySend(nuageVspDevice.getHostId(),syncCmd);
    if (answer != null && answer.getSuccess()) {
      registerNewNuageVspDevice(cmsIdConfig,nuageVspDevice.getId() + "String_Node_Str" + answer.getNuageVspCmsId());
      detail=new DetailVO(host.getId(),"String_Node_Str",answer.getNuageVspCmsId());
      _hostDetailsDao.persist(detail);
      resourceConfiguration.nuageVspCmsId(answer.getNuageVspCmsId());
      resource.configure(cmd.getHostName(),Maps.<String,Object>newHashMap(resourceConfiguration.build()));
      auditDomainsOnVsp((HostVO)host,true,false);
    }
 else {
      throw new CloudRuntimeException("String_Node_Str");
    }
    return nuageVspDevice;
  }
 catch (  ConfigurationException e) {
    s_logger.error("String_Node_Str" + cmd.getHostName(),e);
    throw new CloudRuntimeException("String_Node_Str" + cmd.getHostName(),e);
  }
catch (  ExecutionException ee) {
    s_logger.error("String_Node_Str" + cmd.getHostName(),ee);
    throw new CloudRuntimeException("String_Node_Str" + cmd.getHostName(),ee);
  }
}

Fixed version (ground truth):
@Override public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd){
  final NuageVspResource resource=new NuageVspResource();
  final String deviceName=Network.Provider.NuageVsp.getName();
  ExternalNetworkDeviceManager.NetworkDevice networkDevice=ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
  final Long physicalNetworkId=cmd.getPhysicalNetworkId();
  PhysicalNetworkVO physicalNetwork=_physicalNetworkDao.findById(physicalNetworkId);
  if (physicalNetwork == null) {
    throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
  }
  long zoneId=physicalNetwork.getDataCenterId();
  final PhysicalNetworkServiceProviderVO ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),networkDevice.getNetworkServiceProvder());
  if (ntwkSvcProvider == null) {
    throw new CloudRuntimeException("String_Node_Str" + networkDevice.getNetworkServiceProvder() + "String_Node_Str"+ physicalNetworkId+ "String_Node_Str");
  }
 else   if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
    throw new CloudRuntimeException("String_Node_Str" + ntwkSvcProvider.getProviderName() + "String_Node_Str"+ physicalNetworkId+ "String_Node_Str");
  }
  if (_nuageVspDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  try {
    NuageVspPluginClientLoader clientLoader=NuageVspPluginClientLoader.getClientLoader(null,null,1,1,null);
    Map<String,Object> clientDefaults=clientLoader.getNuageVspManagerClient().getClientDefaults();
    String apiVersion=MoreObjects.firstNonNull(cmd.getApiVersion(),(String)clientDefaults.get("String_Node_Str"));
    if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
      throw new CloudRuntimeException("String_Node_Str" + apiVersion);
    }
    int port=cmd.getPort();
    if (0 == port) {
      port=8443;
    }
    String cmsUserPasswordBase64=NuageVspUtil.encodePassword(cmd.getPassword());
    String retryCount=String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(),clientDefaults.get("String_Node_Str")));
    String retryInterval=String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(),clientDefaults.get("String_Node_Str")));
    NuageVspResource.Configuration resourceConfiguration=new NuageVspResource.Configuration().name("String_Node_Str" + cmd.getHostName()).guid(UUID.randomUUID().toString()).zoneId(String.valueOf(physicalNetwork.getDataCenterId())).hostName(cmd.getHostName()).cmsUser(cmd.getUserName()).cmsUserPassword(cmsUserPasswordBase64).port(String.valueOf(port)).apiVersion(apiVersion).apiRelativePath("String_Node_Str" + apiVersion).retryCount(retryCount).retryInterval(retryInterval);
    Map<String,String> hostDetails=resourceConfiguration.build();
    resource.configure(cmd.getHostName(),Maps.<String,Object>newHashMap(hostDetails));
    Host host=_resourceMgr.addHost(zoneId,resource,Host.Type.L2Networking,hostDetails);
    if (host == null) {
      throw new CloudRuntimeException("String_Node_Str");
    }
    NuageVspDeviceVO nuageVspDevice=new NuageVspDeviceVO(host.getId(),physicalNetworkId,ntwkSvcProvider.getProviderName(),deviceName);
    _nuageVspDao.persist(nuageVspDevice);
    DetailVO detail=new DetailVO(host.getId(),"String_Node_Str",String.valueOf(nuageVspDevice.getId()));
    _hostDetailsDao.persist(detail);
    ConfigurationVO cmsIdConfig=_configDao.findByName("String_Node_Str");
    host=findNuageVspHost(nuageVspDevice.getHostId());
    SyncNuageVspCmsIdCommand syncCmd=new SyncNuageVspCmsIdCommand(SyncType.REGISTER,null);
    SyncNuageVspCmsIdAnswer answer=(SyncNuageVspCmsIdAnswer)_agentMgr.easySend(nuageVspDevice.getHostId(),syncCmd);
    if (answer != null && answer.getSuccess()) {
      registerNewNuageVspDevice(cmsIdConfig,nuageVspDevice.getId() + "String_Node_Str" + answer.getNuageVspCmsId());
      detail=new DetailVO(host.getId(),"String_Node_Str",answer.getNuageVspCmsId());
      _hostDetailsDao.persist(detail);
      resourceConfiguration.nuageVspCmsId(answer.getNuageVspCmsId());
      resource.configure(cmd.getHostName(),Maps.<String,Object>newHashMap(resourceConfiguration.build()));
      auditDomainsOnVsp((HostVO)host,true,false);
    }
 else {
      throw new CloudRuntimeException("String_Node_Str");
    }
    return nuageVspDevice;
  }
 catch (  ConfigurationException e) {
    s_logger.error("String_Node_Str" + cmd.getHostName(),e);
    throw new CloudRuntimeException("String_Node_Str" + cmd.getHostName(),e);
  }
catch (  ExecutionException ee) {
    s_logger.error("String_Node_Str" + cmd.getHostName(),ee);
    throw new CloudRuntimeException("String_Node_Str" + cmd.getHostName(),ee);
  }
}