Program: 106446
Project: 106446
Buggy source:
@Override public boolean applyStaticNats(Network config,List<? extends StaticNat> rules) throws ResourceUnavailableException {
  if (!canHandle(config,Service.StaticNat)) {
    return false;
  }
  boolean multiNetScalerDeployment=Boolean.valueOf(_configDao.getValue(Config.EIPWithMultipleNetScalersEnabled.key()));
  try {
    if (!multiNetScalerDeployment) {
      String errMsg;
      ExternalLoadBalancerDeviceVO lbDevice=getExternalLoadBalancerForNetwork(config);
      if (lbDevice == null) {
        try {
          lbDevice=allocateLoadBalancerForNetwork(config);
        }
 catch (        Exception e) {
          errMsg="String_Node_Str" + e.getMessage();
          s_logger.error(errMsg);
          throw new ResourceUnavailableException(errMsg,this.getClass(),0);
        }
      }
      if (!isNetscalerDevice(lbDevice.getDeviceName())) {
        errMsg="String_Node_Str";
        s_logger.error(errMsg);
        throw new ResourceUnavailableException(errMsg,this.getClass(),0);
      }
      SetStaticNatRulesAnswer answer=null;
      List<StaticNatRuleTO> rulesTO=null;
      if (rules != null) {
        rulesTO=new ArrayList<StaticNatRuleTO>();
        for (        StaticNat rule : rules) {
          IpAddress sourceIp=_networkMgr.getIp(rule.getSourceIpAddressId());
          StaticNatRuleTO ruleTO=new StaticNatRuleTO(0,sourceIp.getAddress().addr(),null,null,rule.getDestIpAddress(),null,null,null,rule.isForRevoke(),false);
          rulesTO.add(ruleTO);
        }
      }
      SetStaticNatRulesCommand cmd=new SetStaticNatRulesCommand(rulesTO);
      answer=(SetStaticNatRulesAnswer)_agentMgr.send(lbDevice.getHostId(),cmd);
      if (answer == null) {
        return false;
      }
 else {
        return answer.getResult();
      }
    }
 else {
      if (rules != null) {
        for (        StaticNat rule : rules) {
          ExternalLoadBalancerDeviceVO lbDevice=getNetScalerForEIP(rule);
          if (lbDevice == null) {
            String errMsg="String_Node_Str" + rule.getDestIpAddress();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg,this.getClass(),0);
          }
          List<StaticNatRuleTO> rulesTO=new ArrayList<StaticNatRuleTO>();
          IpAddress sourceIp=_networkMgr.getIp(rule.getSourceIpAddressId());
          StaticNatRuleTO ruleTO=new StaticNatRuleTO(0,sourceIp.getAddress().addr(),null,null,rule.getDestIpAddress(),null,null,null,rule.isForRevoke(),false);
          rulesTO.add(ruleTO);
          SetStaticNatRulesCommand cmd=new SetStaticNatRulesCommand(rulesTO,null);
          SetStaticNatRulesAnswer answer=(SetStaticNatRulesAnswer)_agentMgr.send(lbDevice.getHostId(),cmd);
          if (answer == null) {
            String errMsg="String_Node_Str" + lbDevice.getHostId();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg,this.getClass(),0);
          }
        }
        return true;
      }
    }
    return true;
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str" + e.getMessage());
    return false;
  }
}

Fixed version (ground truth):
@Override public boolean applyStaticNats(Network config,List<? extends StaticNat> rules) throws ResourceUnavailableException {
  if (!canHandle(config,Service.StaticNat)) {
    return false;
  }
  boolean multiNetScalerDeployment=Boolean.valueOf(_configDao.getValue(Config.EIPWithMultipleNetScalersEnabled.key()));
  try {
    if (!multiNetScalerDeployment) {
      String errMsg;
      ExternalLoadBalancerDeviceVO lbDevice=getExternalLoadBalancerForNetwork(config);
      if (lbDevice == null) {
        try {
          lbDevice=allocateLoadBalancerForNetwork(config);
        }
 catch (        Exception e) {
          errMsg="String_Node_Str" + e.getMessage();
          s_logger.error(errMsg);
          throw new ResourceUnavailableException(errMsg,this.getClass(),0);
        }
      }
      if (!isNetscalerDevice(lbDevice.getDeviceName())) {
        errMsg="String_Node_Str";
        s_logger.error(errMsg);
        throw new ResourceUnavailableException(errMsg,this.getClass(),0);
      }
      SetStaticNatRulesAnswer answer=null;
      List<StaticNatRuleTO> rulesTO=null;
      if (rules != null) {
        rulesTO=new ArrayList<StaticNatRuleTO>();
        for (        StaticNat rule : rules) {
          IpAddress sourceIp=_networkMgr.getIp(rule.getSourceIpAddressId());
          StaticNatRuleTO ruleTO=new StaticNatRuleTO(0,sourceIp.getAddress().addr(),null,null,rule.getDestIpAddress(),null,null,null,rule.isForRevoke(),false);
          rulesTO.add(ruleTO);
        }
      }
      SetStaticNatRulesCommand cmd=new SetStaticNatRulesCommand(rulesTO,null);
      answer=(SetStaticNatRulesAnswer)_agentMgr.send(lbDevice.getHostId(),cmd);
      if (answer == null) {
        return false;
      }
 else {
        return answer.getResult();
      }
    }
 else {
      if (rules != null) {
        for (        StaticNat rule : rules) {
          ExternalLoadBalancerDeviceVO lbDevice=getNetScalerForEIP(rule);
          if (lbDevice == null) {
            String errMsg="String_Node_Str" + rule.getDestIpAddress();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg,this.getClass(),0);
          }
          List<StaticNatRuleTO> rulesTO=new ArrayList<StaticNatRuleTO>();
          IpAddress sourceIp=_networkMgr.getIp(rule.getSourceIpAddressId());
          StaticNatRuleTO ruleTO=new StaticNatRuleTO(0,sourceIp.getAddress().addr(),null,null,rule.getDestIpAddress(),null,null,null,rule.isForRevoke(),false);
          rulesTO.add(ruleTO);
          SetStaticNatRulesCommand cmd=new SetStaticNatRulesCommand(rulesTO,null);
          SetStaticNatRulesAnswer answer=(SetStaticNatRulesAnswer)_agentMgr.send(lbDevice.getHostId(),cmd);
          if (answer == null) {
            String errMsg="String_Node_Str" + lbDevice.getHostId();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg,this.getClass(),0);
          }
        }
        return true;
      }
    }
    return true;
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str" + e.getMessage());
    return false;
  }
}