Program: 106996
Project: 106996
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_LOAD_BALANCER_CREATE,eventDescription="String_Node_Str") public LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException {
  UserContext caller=UserContext.current();
  long ipId=lb.getSourceIpAddressId();
  IPAddressVO ipAddr=_ipAddressDao.findById(ipId);
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  int srcPortStart=lb.getSourcePortStart();
  int srcPortEnd=lb.getSourcePortEnd();
  int defPortStart=lb.getDefaultPortStart();
  int defPortEnd=lb.getDefaultPortEnd();
  if (!NetUtils.isValidPort(srcPortStart)) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortStart);
  }
  if (!NetUtils.isValidPort(srcPortEnd)) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortEnd);
  }
  if (srcPortStart > srcPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortStart + "String_Node_Str"+ srcPortEnd);
  }
  if (!NetUtils.isValidPort(defPortStart)) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortStart);
  }
  if (!NetUtils.isValidPort(defPortEnd)) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortEnd);
  }
  if (defPortStart > defPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortStart + "String_Node_Str"+ defPortEnd);
  }
  if ((lb.getAlgorithm() == null) || !NetUtils.isValidAlgorithm(lb.getAlgorithm())) {
    throw new InvalidParameterValueException("String_Node_Str" + lb.getAlgorithm());
  }
  Long networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  _accountMgr.checkAccess(caller.getCaller(),ipAddr);
  if (!_networkMgr.isServiceSupported(networkId,Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getAlgorithm(),networkId,ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  try {
    _rulesMgr.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);
    return newRule;
  }
 catch (  Exception e) {
    _lbDao.remove(newRule.getId());
    if (e instanceof NetworkRuleConflictException) {
      throw (NetworkRuleConflictException)e;
    }
    throw new CloudRuntimeException("String_Node_Str" + newRule.getSourceIpAddressId(),e);
  }
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_LOAD_BALANCER_CREATE,eventDescription="String_Node_Str") public LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException {
  UserContext caller=UserContext.current();
  long ipId=lb.getSourceIpAddressId();
  IPAddressVO ipAddr=_ipAddressDao.findById(ipId);
  if (ipAddr == null || !ipAddr.readyToUse()) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId);
  }
  int srcPortStart=lb.getSourcePortStart();
  int srcPortEnd=lb.getSourcePortEnd();
  int defPortStart=lb.getDefaultPortStart();
  int defPortEnd=lb.getDefaultPortEnd();
  if (!NetUtils.isValidPort(srcPortStart)) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortStart);
  }
  if (!NetUtils.isValidPort(srcPortEnd)) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortEnd);
  }
  if (srcPortStart > srcPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str" + srcPortStart + "String_Node_Str"+ srcPortEnd);
  }
  if (!NetUtils.isValidPort(defPortStart)) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortStart);
  }
  if (!NetUtils.isValidPort(defPortEnd)) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortEnd);
  }
  if (defPortStart > defPortEnd) {
    throw new InvalidParameterValueException("String_Node_Str" + defPortStart + "String_Node_Str"+ defPortEnd);
  }
  if ((lb.getAlgorithm() == null) || !NetUtils.isValidAlgorithm(lb.getAlgorithm())) {
    throw new InvalidParameterValueException("String_Node_Str" + lb.getAlgorithm());
  }
  Long networkId=ipAddr.getAssociatedWithNetworkId();
  if (networkId == null) {
    throw new InvalidParameterValueException("String_Node_Str" + ipId + "String_Node_Str");
  }
  _accountMgr.checkAccess(caller.getCaller(),ipAddr);
  Network network=_networkMgr.getNetwork(networkId);
  if (!_networkMgr.isServiceSupported(network.getNetworkOfferingId(),Service.Lb)) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  LoadBalancerVO newRule=new LoadBalancerVO(lb.getXid(),lb.getName(),lb.getDescription(),lb.getSourceIpAddressId(),lb.getSourcePortEnd(),lb.getDefaultPortStart(),lb.getAlgorithm(),networkId,ipAddr.getAccountId(),ipAddr.getDomainId());
  newRule=_lbDao.persist(newRule);
  try {
    _rulesMgr.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);
    return newRule;
  }
 catch (  Exception e) {
    _lbDao.remove(newRule.getId());
    if (e instanceof NetworkRuleConflictException) {
      throw (NetworkRuleConflictException)e;
    }
    throw new CloudRuntimeException("String_Node_Str" + newRule.getSourceIpAddressId(),e);
  }
}