Program: 106757
Project: 106757
Buggy source:
@Override @DB public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb,Account account) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
  Long ipId=lb.getSourceIpAddressId();
  if (ipId != null && getNetworkToDeployLb(ipId) == null) {
    return null;
  }
  boolean newIp=false;
  account=_accountDao.acquireInLockTable(account.getId());
  if (account == null) {
    s_logger.warn("String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str");
  }
  try {
    List<LoadBalancerVO> existingLbs=findExistingLoadBalancers(lb.getName(),lb.getSourceIpAddressId(),lb.getAccountId(),lb.getDomainId(),lb.getSourcePortStart());
    if (existingLbs == null) {
      existingLbs=findExistingLoadBalancers(lb.getName(),lb.getSourceIpAddressId(),lb.getAccountId(),lb.getDomainId(),null);
      if (existingLbs == null) {
        if (lb.getSourceIpAddressId() != null) {
          existingLbs=findExistingLoadBalancers(lb.getName(),null,lb.getAccountId(),lb.getDomainId(),null);
          if (existingLbs != null) {
            throw new InvalidParameterValueException("String_Node_Str" + lb.getName() + "String_Node_Str"+ lb.getSourceIpAddressId());
          }
        }
 else {
          s_logger.debug("String_Node_Str");
          PublicIp ip=allocIp(lb,account);
          ipId=ip.getId();
          newIp=true;
        }
      }
 else {
        ipId=existingLbs.get(0).getSourceIpAddressId();
        s_logger.debug("String_Node_Str" + ipId);
      }
    }
 else {
      s_logger.warn("String_Node_Str");
      throw new NetworkRuleConflictException("String_Node_Str");
    }
    NetworkVO network=getNetworkToDeployLb(ipId);
    IPAddressVO ipAddr=_ipAddressDao.findById(ipId);
    long networkId=network.getId();
    LoadBalancer result=null;
    try {
      lb.setSourceIpAddressId(ipId);
      result=_lbMgr.createLoadBalancer(lb);
    }
 catch (    NetworkRuleConflictException e) {
      s_logger.warn("String_Node_Str");
      if (newIp) {
        releaseIp(ipId,UserContext.current().getCallerUserId(),account);
      }
      throw e;
    }
    DomainRouterVO elbVm=null;
    if (existingLbs == null) {
      elbVm=findELBVmWithCapacity(network,ipAddr);
      if (elbVm == null) {
        elbVm=deployLoadBalancerVM(networkId,ipAddr,account.getId());
        if (elbVm == null) {
          s_logger.warn("String_Node_Str" + ipAddr + "String_Node_Str"+ network+ "String_Node_Str"+ lb.getName());
          if (newIp)           releaseIp(ipId,UserContext.current().getCallerUserId(),account);
        }
      }
    }
 else {
      ElasticLbVmMapVO elbVmMap=_elbVmMapDao.findOneByIp(ipId);
      if (elbVmMap != null) {
        elbVm=_routerDao.findById(elbVmMap.getElbVmId());
      }
    }
    if (elbVm == null) {
      s_logger.warn("String_Node_Str");
      s_logger.warn("String_Node_Str");
      _lbDao.remove(result.getId());
      return null;
    }
    ElasticLbVmMapVO mapping=new ElasticLbVmMapVO(ipId,elbVm.getId(),result.getId());
    _elbVmMapDao.persist(mapping);
    return result;
  }
  finally {
    if (account != null) {
      _accountDao.releaseFromLockTable(account.getId());
    }
  }
}

Fixed version (ground truth):
@Override @DB public LoadBalancer handleCreateLoadBalancerRule(CreateLoadBalancerRuleCmd lb,Account account) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
  Long ipId=lb.getSourceIpAddressId();
  if (ipId != null && getNetworkToDeployLb(ipId) == null) {
    return null;
  }
  boolean newIp=false;
  account=_accountDao.acquireInLockTable(account.getId());
  if (account == null) {
    s_logger.warn("String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str");
  }
  try {
    List<LoadBalancerVO> existingLbs=findExistingLoadBalancers(lb.getName(),lb.getSourceIpAddressId(),lb.getAccountId(),lb.getDomainId(),lb.getSourcePortStart());
    if (existingLbs == null) {
      existingLbs=findExistingLoadBalancers(lb.getName(),lb.getSourceIpAddressId(),lb.getAccountId(),lb.getDomainId(),null);
      if (existingLbs == null) {
        if (lb.getSourceIpAddressId() != null) {
          existingLbs=findExistingLoadBalancers(lb.getName(),null,lb.getAccountId(),lb.getDomainId(),null);
          if (existingLbs != null) {
            throw new InvalidParameterValueException("String_Node_Str" + lb.getName() + "String_Node_Str"+ lb.getSourceIpAddressId());
          }
        }
 else {
          s_logger.debug("String_Node_Str");
          PublicIp ip=allocIp(lb,account);
          ipId=ip.getId();
          newIp=true;
        }
      }
 else {
        ipId=existingLbs.get(0).getSourceIpAddressId();
        s_logger.debug("String_Node_Str" + ipId);
      }
    }
 else {
      s_logger.warn("String_Node_Str");
      throw new NetworkRuleConflictException("String_Node_Str");
    }
    NetworkVO network=getNetworkToDeployLb(ipId);
    IPAddressVO ipAddr=_ipAddressDao.findById(ipId);
    long networkId=network.getId();
    LoadBalancer result=null;
    try {
      lb.setSourceIpAddressId(ipId);
      result=_lbMgr.createLoadBalancer(lb,false);
    }
 catch (    NetworkRuleConflictException e) {
      s_logger.warn("String_Node_Str");
      if (newIp) {
        releaseIp(ipId,UserContext.current().getCallerUserId(),account);
      }
      throw e;
    }
    DomainRouterVO elbVm=null;
    if (existingLbs == null) {
      elbVm=findELBVmWithCapacity(network,ipAddr);
      if (elbVm == null) {
        elbVm=deployLoadBalancerVM(networkId,ipAddr,account.getId());
        if (elbVm == null) {
          s_logger.warn("String_Node_Str" + ipAddr + "String_Node_Str"+ network+ "String_Node_Str"+ lb.getName());
          if (newIp)           releaseIp(ipId,UserContext.current().getCallerUserId(),account);
        }
      }
    }
 else {
      ElasticLbVmMapVO elbVmMap=_elbVmMapDao.findOneByIp(ipId);
      if (elbVmMap != null) {
        elbVm=_routerDao.findById(elbVmMap.getElbVmId());
      }
    }
    if (elbVm == null) {
      s_logger.warn("String_Node_Str");
      s_logger.warn("String_Node_Str");
      _lbDao.remove(result.getId());
      return null;
    }
    ElasticLbVmMapVO mapping=new ElasticLbVmMapVO(ipId,elbVm.getId(),result.getId());
    _elbVmMapDao.persist(mapping);
    return result;
  }
  finally {
    if (account != null) {
      _accountDao.releaseFromLockTable(account.getId());
    }
  }
}