Program: 89382
Project: 89382
Buggy source:
@DB public LoadBalancer createLoadBalancer(CreateLoadBalancerRuleCmd lb) throws NetworkRuleConflictException {
  long ipId=lb.getSourceIpAddressId();
  UserContext caller=UserContext.current();
  int srcPortStart=lb.getSourcePortStart();
  int defPortStart=lb.getDefaultPortStart();
  IPAddressVO ipAddr=_ipAddressDao.findById(lb.getSourceIpAddressId());
  Long networkId=ipAddr.getSourceNetworkId();
  NetworkVO network=_networkDao.findById(networkId);
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  _accountMgr.checkAccess(caller.getCaller(),ipAddr);
  if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(),Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  if (openFirewall) {
    _firewallMgr.createRuleForAllCidrs(ipId,caller.getCaller(),lb.getSourcePortStart(),lb.getSourcePortEnd(),lb.getProtocol(),null,null);
  }
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getSourceCidrList(),lb.getAlgorithm(),network.getId(),ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  boolean success=true;
  try {
    _firewallMgr.detectRulesConflict(newRule,ipAddr);
    if (!_rulesDao.setStateToAdd(newRule)) {
      throw new CloudRuntimeException("String_Node_Str" + newRule);
    }
    s_logger.debug("String_Node_Str" + newRule.getId() + "String_Node_Str"+ ipId+ "String_Node_Str"+ srcPortStart+ "String_Node_Str"+ defPortStart+ "String_Node_Str");
    UserContext.current().setEventDetails("String_Node_Str" + newRule.getId());
    UsageEventVO usageEvent=new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_CREATE,ipAddr.getAllocatedToAccountId(),ipAddr.getDataCenterId(),newRule.getId(),null);
    _usageEventDao.persist(usageEvent);
    txn.commit();
    if (openFirewall) {
      success=success && _firewallMgr.applyFirewallRules(lb.getSourceIpAddressId(),caller.getCaller());
    }
    return newRule;
  }
 catch (  Exception e) {
    success=false;
    if (e instanceof NetworkRuleConflictException) {
      throw (NetworkRuleConflictException)e;
    }
    throw new CloudRuntimeException("String_Node_Str" + newRule.getSourceIpAddressId(),e);
  }
 finally {
    if (!success) {
      _lbDao.remove(newRule.getId());
    }
  }
}

Fixed version (ground truth):
@DB public LoadBalancer createLoadBalancer(CreateLoadBalancerRuleCmd lb,boolean openFirewall) throws NetworkRuleConflictException {
  long ipId=lb.getSourceIpAddressId();
  UserContext caller=UserContext.current();
  int srcPortStart=lb.getSourcePortStart();
  int defPortStart=lb.getDefaultPortStart();
  int srcPortEnd=lb.getSourcePortEnd();
  IPAddressVO ipAddr=_ipAddressDao.findById(lb.getSourceIpAddressId());
  Long networkId=ipAddr.getSourceNetworkId();
  NetworkVO network=_networkDao.findById(networkId);
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  _firewallMgr.validateFirewallRule(caller.getCaller(),ipAddr,srcPortStart,srcPortEnd,lb.getProtocol());
  networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  _accountMgr.checkAccess(caller.getCaller(),ipAddr);
  if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(),Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  if (openFirewall) {
    _firewallMgr.createRuleForAllCidrs(ipId,caller.getCaller(),lb.getSourcePortStart(),lb.getSourcePortEnd(),lb.getProtocol(),null,null);
  }
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getSourceCidrList(),lb.getAlgorithm(),network.getId(),ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  boolean success=true;
  try {
    _firewallMgr.detectRulesConflict(newRule,ipAddr);
    if (!_rulesDao.setStateToAdd(newRule)) {
      throw new CloudRuntimeException("String_Node_Str" + newRule);
    }
    s_logger.debug("String_Node_Str" + newRule.getId() + "String_Node_Str"+ ipId+ "String_Node_Str"+ srcPortStart+ "String_Node_Str"+ defPortStart+ "String_Node_Str");
    UserContext.current().setEventDetails("String_Node_Str" + newRule.getId());
    UsageEventVO usageEvent=new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_CREATE,ipAddr.getAllocatedToAccountId(),ipAddr.getDataCenterId(),newRule.getId(),null);
    _usageEventDao.persist(usageEvent);
    txn.commit();
    if (openFirewall) {
      success=success && _firewallMgr.applyFirewallRules(lb.getSourceIpAddressId(),caller.getCaller());
    }
    return newRule;
  }
 catch (  Exception e) {
    success=false;
    if (e instanceof NetworkRuleConflictException) {
      throw (NetworkRuleConflictException)e;
    }
    throw new CloudRuntimeException("String_Node_Str" + newRule.getSourceIpAddressId(),e);
  }
 finally {
    if (!success) {
      _lbDao.remove(newRule.getId());
    }
  }
}