Program: 105428
Project: 105428
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_NET_RULE_MODIFY,eventDescription="String_Node_Str",async=true) public PortForwardingRule updatePortForwardingRule(long id,Integer privatePort,Long virtualMachineId,Ip vmGuestIp,String customId,Boolean forDisplay){
  Account caller=CallContext.current().getCallingAccount();
  PortForwardingRuleVO rule=_portForwardingDao.findById(id);
  if (rule == null) {
    throw new InvalidParameterValueException("String_Node_Str" + id);
  }
  _accountMgr.checkAccess(caller,null,true,rule);
  if (customId != null) {
    rule.setUuid(customId);
  }
  if (forDisplay != null) {
    rule.setDisplay(forDisplay);
  }
  if (rule.getSourcePortStart() != rule.getSourcePortEnd() && privatePort != null) {
    throw new InvalidParameterValueException("String_Node_Str" + rule.getSourcePortStart() + "String_Node_Str"+ rule.getSourcePortEnd());
  }
  if (virtualMachineId == null && vmGuestIp != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Ip dstIp=rule.getDestinationIpAddress();
  if (virtualMachineId != null) {
    Nic guestNic=_networkModel.getNicInNetwork(virtualMachineId,rule.getNetworkId());
    if (guestNic == null || guestNic.getIp4Address() == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else {
      dstIp=new Ip(guestNic.getIp4Address());
    }
    if (vmGuestIp != null) {
      if (!dstIp.equals(vmGuestIp)) {
        NicSecondaryIp secondaryIp=_nicSecondaryDao.findByIp4AddressAndNicId(vmGuestIp.toString(),guestNic.getId());
        if (secondaryIp == null) {
          throw new InvalidParameterValueException("String_Node_Str");
        }
        dstIp=vmGuestIp;
      }
    }
  }
  List<PortForwardingRuleVO> rules=new ArrayList<PortForwardingRuleVO>();
  rule.setState(State.Revoke);
  _portForwardingDao.update(id,rule);
  rules.add(rule);
  try {
    if (!_firewallMgr.applyRules(rules,true,false)) {
      throw new CloudRuntimeException("String_Node_Str" + id);
    }
  }
 catch (  ResourceUnavailableException ex) {
    throw new CloudRuntimeException("String_Node_Str" + id + "String_Node_Str",ex);
  }
  rule=_portForwardingDao.findById(id);
  rule.setState(State.Add);
  if (privatePort != null) {
    rule.setDestinationPortStart(privatePort.intValue());
    rule.setDestinationPortEnd(privatePort.intValue());
  }
  if (virtualMachineId != null) {
    rule.setVirtualMachineId(virtualMachineId);
    rule.setDestinationIpAddress(dstIp);
  }
  _portForwardingDao.update(id,rule);
  if (!applyPortForwardingRules(rule.getSourceIpAddressId(),false,caller)) {
    throw new CloudRuntimeException("String_Node_Str" + id);
  }
  return _portForwardingDao.findById(id);
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_NET_RULE_MODIFY,eventDescription="String_Node_Str",async=true) public PortForwardingRule updatePortForwardingRule(long id,Integer privatePort,Long virtualMachineId,Ip vmGuestIp,String customId,Boolean forDisplay){
  Account caller=CallContext.current().getCallingAccount();
  PortForwardingRuleVO rule=_portForwardingDao.findById(id);
  if (rule == null) {
    throw new InvalidParameterValueException("String_Node_Str" + id);
  }
  _accountMgr.checkAccess(caller,null,true,rule);
  if (customId != null) {
    rule.setUuid(customId);
  }
  if (forDisplay != null) {
    rule.setDisplay(forDisplay);
  }
  if (!rule.getSourcePortStart().equals(rule.getSourcePortEnd()) && privatePort != null) {
    throw new InvalidParameterValueException("String_Node_Str" + rule.getSourcePortStart() + "String_Node_Str"+ rule.getSourcePortEnd());
  }
  if (virtualMachineId == null && vmGuestIp != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Ip dstIp=rule.getDestinationIpAddress();
  if (virtualMachineId != null) {
    Nic guestNic=_networkModel.getNicInNetwork(virtualMachineId,rule.getNetworkId());
    if (guestNic == null || guestNic.getIp4Address() == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else {
      dstIp=new Ip(guestNic.getIp4Address());
    }
    if (vmGuestIp != null) {
      if (!dstIp.equals(vmGuestIp)) {
        NicSecondaryIp secondaryIp=_nicSecondaryDao.findByIp4AddressAndNicId(vmGuestIp.toString(),guestNic.getId());
        if (secondaryIp == null) {
          throw new InvalidParameterValueException("String_Node_Str");
        }
        dstIp=vmGuestIp;
      }
    }
  }
  List<PortForwardingRuleVO> rules=new ArrayList<PortForwardingRuleVO>();
  rule.setState(State.Revoke);
  _portForwardingDao.update(id,rule);
  rules.add(rule);
  try {
    if (!_firewallMgr.applyRules(rules,true,false)) {
      throw new CloudRuntimeException("String_Node_Str" + id);
    }
  }
 catch (  ResourceUnavailableException ex) {
    throw new CloudRuntimeException("String_Node_Str" + id + "String_Node_Str",ex);
  }
  rule=_portForwardingDao.findById(id);
  rule.setState(State.Add);
  if (privatePort != null) {
    rule.setDestinationPortStart(privatePort.intValue());
    rule.setDestinationPortEnd(privatePort.intValue());
  }
  if (virtualMachineId != null) {
    rule.setVirtualMachineId(virtualMachineId);
    rule.setDestinationIpAddress(dstIp);
  }
  _portForwardingDao.update(id,rule);
  if (!applyPortForwardingRules(rule.getSourceIpAddressId(),false,caller)) {
    throw new CloudRuntimeException("String_Node_Str" + id);
  }
  return _portForwardingDao.findById(id);
}