Program: 89313
Project: 89313
Buggy source:
@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();
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  _firewallMgr.validateFirewallRule(caller.getCaller(),ipAddr,srcPortStart,srcPortEnd,lb.getProtocol(),Purpose.LoadBalancing);
  networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  NetworkVO network=_networkDao.findById(networkId);
  _accountMgr.checkAccess(caller.getCaller(),null,ipAddr);
  if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(),Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getAlgorithm(),network.getId(),ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  if (openFirewall) {
    _firewallMgr.createRuleForAllCidrs(ipId,caller.getCaller(),lb.getSourcePortStart(),lb.getSourcePortEnd(),lb.getProtocol(),null,null,newRule.getId());
  }
  boolean success=true;
  try {
    _firewallMgr.detectRulesConflict(newRule,ipAddr);
    if (!_firewallDao.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();
    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) {
      txn.start();
      _firewallMgr.revokeRelatedFirewallRule(newRule.getId(),false);
      _lbDao.remove(newRule.getId());
      txn.commit();
    }
  }
}

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();
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  _firewallMgr.validateFirewallRule(caller.getCaller(),ipAddr,srcPortStart,srcPortEnd,lb.getProtocol(),Purpose.LoadBalancing);
  networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  NetworkVO network=_networkDao.findById(networkId);
  _accountMgr.checkAccess(caller.getCaller(),null,ipAddr);
  if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(),Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getAlgorithm(),network.getId(),ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  if (openFirewall) {
    _firewallMgr.createRuleForAllCidrs(ipId,caller.getCaller(),lb.getSourcePortStart(),lb.getSourcePortEnd(),lb.getProtocol(),null,null,newRule.getId());
  }
  boolean success=true;
  try {
    _firewallMgr.detectRulesConflict(newRule,ipAddr);
    if (!_firewallDao.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();
    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 && newRule != null) {
      txn.start();
      _firewallMgr.revokeRelatedFirewallRule(newRule.getId(),false);
      _lbDao.remove(newRule.getId());
      txn.commit();
    }
  }
}