Program: 106275
Project: 106275
Buggy source:
@Override @DB public ExternalLoadBalancerDeviceVO addExternalLoadBalancer(long physicalNetworkId,String url,String username,String password,String deviceName,ServerResource resource,boolean gslbProvider,String gslbSitePublicIp,String gslbSitePrivateIp){
  PhysicalNetworkVO pNetwork=null;
  NetworkDevice ntwkDevice=NetworkDevice.getNetworkDevice(deviceName);
  long zoneId;
  if ((ntwkDevice == null) || (url == null) || (username == null)|| (resource == null)|| (password == null)) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  pNetwork=_physicalNetworkDao.findById(physicalNetworkId);
  if (pNetwork == null) {
    throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
  }
  zoneId=pNetwork.getDataCenterId();
  PhysicalNetworkServiceProviderVO ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),ntwkDevice.getNetworkServiceProvder());
  if (gslbProvider) {
    ExternalLoadBalancerDeviceVO zoneGslbProvider=_externalLoadBalancerDeviceDao.findGslbServiceProvider(physicalNetworkId,ntwkDevice.getNetworkServiceProvder());
    if (zoneGslbProvider != null) {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
 else {
    ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),ntwkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
      throw new CloudRuntimeException("String_Node_Str" + ntwkDevice.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");
    }
  }
  URI uri;
  try {
    uri=new URI(url);
  }
 catch (  Exception e) {
    s_logger.debug(e);
    throw new InvalidParameterValueException(e.getMessage());
  }
  String ipAddress=uri.getHost();
  Map hostDetails=new HashMap<String,String>();
  String hostName=getExternalLoadBalancerResourceGuid(pNetwork.getId(),deviceName,ipAddress);
  hostDetails.put("String_Node_Str",hostName);
  hostDetails.put("String_Node_Str",UUID.randomUUID().toString());
  hostDetails.put("String_Node_Str",String.valueOf(pNetwork.getDataCenterId()));
  hostDetails.put("String_Node_Str",ipAddress);
  hostDetails.put("String_Node_Str",String.valueOf(pNetwork.getId()));
  hostDetails.put("String_Node_Str",username);
  hostDetails.put("String_Node_Str",password);
  hostDetails.put("String_Node_Str",deviceName);
  Map<String,String> configParams=new HashMap<String,String>();
  UrlUtil.parseQueryParameters(uri.getQuery(),false,configParams);
  hostDetails.putAll(configParams);
  Transaction txn=Transaction.currentTxn();
  try {
    resource.configure(hostName,hostDetails);
    Host host=_resourceMgr.addHost(zoneId,resource,Host.Type.ExternalLoadBalancer,hostDetails);
    if (host != null) {
      boolean dedicatedUse=(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null) ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
      long capacity=NumbersUtil.parseLong(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY),0);
      if (capacity == 0) {
        capacity=_defaultLbCapacity;
      }
      ExternalLoadBalancerDeviceVO lbDeviceVO;
      txn.start();
      lbDeviceVO=new ExternalLoadBalancerDeviceVO(host.getId(),pNetwork.getId(),ntwkDevice.getNetworkServiceProvder(),deviceName,capacity,dedicatedUse,gslbProvider);
      if (gslbProvider) {
        lbDeviceVO.setGslbSitePrivateIP(gslbSitePublicIp);
        lbDeviceVO.setGslbSitePrivateIP(gslbSitePrivateIp);
      }
      _externalLoadBalancerDeviceDao.persist(lbDeviceVO);
      DetailVO hostDetail=new DetailVO(host.getId(),ApiConstants.LOAD_BALANCER_DEVICE_ID,String.valueOf(lbDeviceVO.getId()));
      _hostDetailDao.persist(hostDetail);
      txn.commit();
      return lbDeviceVO;
    }
 else {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
 catch (  ConfigurationException e) {
    txn.rollback();
    throw new CloudRuntimeException(e.getMessage());
  }
}

Fixed version (ground truth):
@Override @DB public ExternalLoadBalancerDeviceVO addExternalLoadBalancer(long physicalNetworkId,String url,String username,String password,String deviceName,ServerResource resource,boolean gslbProvider,String gslbSitePublicIp,String gslbSitePrivateIp){
  PhysicalNetworkVO pNetwork=null;
  NetworkDevice ntwkDevice=NetworkDevice.getNetworkDevice(deviceName);
  long zoneId;
  if ((ntwkDevice == null) || (url == null) || (username == null)|| (resource == null)|| (password == null)) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  pNetwork=_physicalNetworkDao.findById(physicalNetworkId);
  if (pNetwork == null) {
    throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
  }
  zoneId=pNetwork.getDataCenterId();
  PhysicalNetworkServiceProviderVO ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),ntwkDevice.getNetworkServiceProvder());
  if (gslbProvider) {
    ExternalLoadBalancerDeviceVO zoneGslbProvider=_externalLoadBalancerDeviceDao.findGslbServiceProvider(physicalNetworkId,ntwkDevice.getNetworkServiceProvder());
    if (zoneGslbProvider != null) {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
 else {
    ntwkSvcProvider=_physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(),ntwkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
      throw new CloudRuntimeException("String_Node_Str" + ntwkDevice.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");
    }
  }
  URI uri;
  try {
    uri=new URI(url);
  }
 catch (  Exception e) {
    s_logger.debug(e);
    throw new InvalidParameterValueException(e.getMessage());
  }
  String ipAddress=uri.getHost();
  Map hostDetails=new HashMap<String,String>();
  String hostName=getExternalLoadBalancerResourceGuid(pNetwork.getId(),deviceName,ipAddress);
  hostDetails.put("String_Node_Str",hostName);
  hostDetails.put("String_Node_Str",UUID.randomUUID().toString());
  hostDetails.put("String_Node_Str",String.valueOf(pNetwork.getDataCenterId()));
  hostDetails.put("String_Node_Str",ipAddress);
  hostDetails.put("String_Node_Str",String.valueOf(pNetwork.getId()));
  hostDetails.put("String_Node_Str",username);
  hostDetails.put("String_Node_Str",password);
  hostDetails.put("String_Node_Str",deviceName);
  Map<String,String> configParams=new HashMap<String,String>();
  UrlUtil.parseQueryParameters(uri.getQuery(),false,configParams);
  hostDetails.putAll(configParams);
  Transaction txn=Transaction.currentTxn();
  try {
    resource.configure(hostName,hostDetails);
    Host host=_resourceMgr.addHost(zoneId,resource,Host.Type.ExternalLoadBalancer,hostDetails);
    if (host != null) {
      boolean dedicatedUse=(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null) ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
      long capacity=NumbersUtil.parseLong(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_CAPACITY),0);
      if (capacity == 0) {
        capacity=_defaultLbCapacity;
      }
      ExternalLoadBalancerDeviceVO lbDeviceVO;
      txn.start();
      lbDeviceVO=new ExternalLoadBalancerDeviceVO(host.getId(),pNetwork.getId(),ntwkDevice.getNetworkServiceProvder(),deviceName,capacity,dedicatedUse,gslbProvider);
      if (gslbProvider) {
        lbDeviceVO.setGslbSitePublicIP(gslbSitePublicIp);
        lbDeviceVO.setGslbSitePrivateIP(gslbSitePrivateIp);
      }
      _externalLoadBalancerDeviceDao.persist(lbDeviceVO);
      DetailVO hostDetail=new DetailVO(host.getId(),ApiConstants.LOAD_BALANCER_DEVICE_ID,String.valueOf(lbDeviceVO.getId()));
      _hostDetailDao.persist(hostDetail);
      txn.commit();
      return lbDeviceVO;
    }
 else {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
 catch (  ConfigurationException e) {
    txn.rollback();
    throw new CloudRuntimeException(e.getMessage());
  }
}