Program: 105547
Project: 105547
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_LOAD_BALANCER_CREATE,eventDescription="String_Node_Str") public LoadBalancer createPublicLoadBalancerRule(String xId,String name,String description,int srcPortStart,int srcPortEnd,int defPortStart,int defPortEnd,Long ipAddrId,String protocol,String algorithm,long networkId,long lbOwnerId,boolean openFirewall,String lbProtocol,Boolean forDisplay) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
  Account lbOwner=_accountMgr.getAccount(lbOwnerId);
  if (srcPortStart != srcPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  IPAddressVO ipVO=null;
  if (ipAddrId != null) {
    ipVO=_ipAddressDao.findById(ipAddrId);
  }
  Network network=_networkModel.getNetwork(networkId);
  LoadBalancer result=null;
  if (result == null) {
    IpAddress systemIp=null;
    NetworkOffering off=_entityMgr.findById(NetworkOffering.class,network.getNetworkOfferingId());
    if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
      systemIp=_ipAddrMgr.assignSystemIp(networkId,lbOwner,true,false);
      ipVO=_ipAddressDao.findById(systemIp.getId());
    }
    if (ipVO == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else     if (ipVO.isOneToOneNat()) {
      throw new NetworkRuleConflictException("String_Node_Str" + ipVO.getAddress());
    }
    boolean performedIpAssoc=false;
    try {
      if (ipVO.getAssociatedWithNetworkId() == null) {
        boolean assignToVpcNtwk=network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
        if (assignToVpcNtwk) {
          _networkModel.checkIpForService(ipVO,Service.Lb,networkId);
          s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
          ipVO=_ipAddrMgr.associateIPToGuestNetwork(ipAddrId,networkId,false);
          performedIpAssoc=true;
        }
      }
 else {
        _networkModel.checkIpForService(ipVO,Service.Lb,null);
      }
      if (ipVO.getAssociatedWithNetworkId() == null) {
        throw new InvalidParameterValueException("String_Node_Str" + ipVO + "String_Node_Str"+ network);
      }
      result=createPublicLoadBalancer(xId,name,description,srcPortStart,defPortStart,ipVO.getId(),protocol,algorithm,openFirewall,CallContext.current(),lbProtocol,forDisplay);
    }
 catch (    Exception ex) {
      s_logger.warn("String_Node_Str",ex);
      if (ex instanceof NetworkRuleConflictException) {
        throw (NetworkRuleConflictException)ex;
      }
      if (ex instanceof InvalidParameterValueException) {
        throw (InvalidParameterValueException)ex;
      }
    }
 finally {
      if (result == null && systemIp != null) {
        s_logger.debug("String_Node_Str" + systemIp + "String_Node_Str");
        _ipAddrMgr.handleSystemIpRelease(systemIp);
      }
      if (performedIpAssoc) {
        ipVO=_ipAddressDao.findById(ipVO.getId());
        _vpcMgr.unassignIPFromVpcNetwork(ipVO.getId(),networkId);
      }
    }
  }
  if (result == null) {
    throw new CloudRuntimeException("String_Node_Str" + name);
  }
  return result;
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_LOAD_BALANCER_CREATE,eventDescription="String_Node_Str") public LoadBalancer createPublicLoadBalancerRule(String xId,String name,String description,int srcPortStart,int srcPortEnd,int defPortStart,int defPortEnd,Long ipAddrId,String protocol,String algorithm,long networkId,long lbOwnerId,boolean openFirewall,String lbProtocol,Boolean forDisplay) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
  Account lbOwner=_accountMgr.getAccount(lbOwnerId);
  if (srcPortStart != srcPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  IPAddressVO ipVO=null;
  if (ipAddrId != null) {
    ipVO=_ipAddressDao.findById(ipAddrId);
  }
  Network network=_networkModel.getNetwork(networkId);
  LoadBalancer result=null;
  if (result == null) {
    IpAddress systemIp=null;
    NetworkOffering off=_entityMgr.findById(NetworkOffering.class,network.getNetworkOfferingId());
    if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
      systemIp=_ipAddrMgr.assignSystemIp(networkId,lbOwner,true,false);
      if (systemIp != null) {
        ipVO=_ipAddressDao.findById(systemIp.getId());
      }
    }
    if (ipVO == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else     if (ipVO.isOneToOneNat()) {
      throw new NetworkRuleConflictException("String_Node_Str" + ipVO.getAddress());
    }
    boolean performedIpAssoc=false;
    try {
      if (ipVO.getAssociatedWithNetworkId() == null) {
        boolean assignToVpcNtwk=network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
        if (assignToVpcNtwk) {
          _networkModel.checkIpForService(ipVO,Service.Lb,networkId);
          s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
          ipVO=_ipAddrMgr.associateIPToGuestNetwork(ipAddrId,networkId,false);
          performedIpAssoc=true;
        }
      }
 else {
        _networkModel.checkIpForService(ipVO,Service.Lb,null);
      }
      if (ipVO.getAssociatedWithNetworkId() == null) {
        throw new InvalidParameterValueException("String_Node_Str" + ipVO + "String_Node_Str"+ network);
      }
      result=createPublicLoadBalancer(xId,name,description,srcPortStart,defPortStart,ipVO.getId(),protocol,algorithm,openFirewall,CallContext.current(),lbProtocol,forDisplay);
    }
 catch (    Exception ex) {
      s_logger.warn("String_Node_Str",ex);
      if (ex instanceof NetworkRuleConflictException) {
        throw (NetworkRuleConflictException)ex;
      }
      if (ex instanceof InvalidParameterValueException) {
        throw (InvalidParameterValueException)ex;
      }
    }
 finally {
      if (result == null && systemIp != null) {
        s_logger.debug("String_Node_Str" + systemIp + "String_Node_Str");
        _ipAddrMgr.handleSystemIpRelease(systemIp);
      }
      if (performedIpAssoc) {
        ipVO=_ipAddressDao.findById(ipVO.getId());
        _vpcMgr.unassignIPFromVpcNetwork(ipVO.getId(),networkId);
      }
    }
  }
  if (result == null) {
    throw new CloudRuntimeException("String_Node_Str" + name);
  }
  return result;
}