Program: 106005
Project: 106005
Buggy source:
@Override public boolean applyStaticNats(List<? extends StaticNat> staticNats,boolean continueOnError,boolean forRevoke) throws ResourceUnavailableException {
  Network network=_networksDao.findById(staticNats.get(0).getNetworkId());
  boolean success=true;
  if (staticNats == null || staticNats.size() == 0) {
    s_logger.debug("String_Node_Str");
    return true;
  }
  List<IPAddressVO> userIps=_ipAddressDao.listByAssociatedNetwork(network.getId(),null);
  List<PublicIp> publicIps=new ArrayList<PublicIp>();
  if (userIps != null && !userIps.isEmpty()) {
    for (    IPAddressVO userIp : userIps) {
      PublicIp publicIp=PublicIp.createFromAddrAndVlan(userIp,_vlanDao.findById(userIp.getVlanId()));
      publicIps.add(publicIp);
    }
  }
  if (checkStaticNatIPAssocRequired(network,false,forRevoke,publicIps)) {
    applyIpAssociations(network,false,continueOnError,publicIps);
  }
  StaticNatServiceProvider element=_networkMgr.getStaticNatProviderForNetwork(network);
  try {
    success=element.applyStaticNats(network,staticNats);
  }
 catch (  ResourceUnavailableException e) {
    if (!continueOnError) {
      throw e;
    }
    s_logger.warn("String_Node_Str" + element.getName() + "String_Node_Str",e);
    success=false;
  }
  for (  StaticNat staticNat : staticNats) {
    if (staticNat.isForRevoke()) {
      for (      PublicIp publicIp : publicIps) {
        if (publicIp.getId() == staticNat.getSourceIpAddressId()) {
          publicIps.remove(publicIp);
          IPAddressVO ip=_ipAddressDao.findByIdIncludingRemoved(staticNat.getSourceIpAddressId());
          ip.setAssociatedWithVmId(null);
          publicIp=PublicIp.createFromAddrAndVlan(ip,_vlanDao.findById(ip.getVlanId()));
          publicIps.add(publicIp);
          break;
        }
      }
    }
  }
  if (checkStaticNatIPAssocRequired(network,true,forRevoke,publicIps)) {
    applyIpAssociations(network,true,continueOnError,publicIps);
  }
  return success;
}

Fixed version (ground truth):
@Override public boolean applyStaticNats(List<? extends StaticNat> staticNats,boolean continueOnError,boolean forRevoke) throws ResourceUnavailableException {
  if (staticNats == null || staticNats.size() == 0) {
    s_logger.debug("String_Node_Str");
    return true;
  }
  Network network=_networksDao.findById(staticNats.get(0).getNetworkId());
  boolean success=true;
  List<IPAddressVO> userIps=_ipAddressDao.listByAssociatedNetwork(network.getId(),null);
  List<PublicIp> publicIps=new ArrayList<PublicIp>();
  if (userIps != null && !userIps.isEmpty()) {
    for (    IPAddressVO userIp : userIps) {
      PublicIp publicIp=PublicIp.createFromAddrAndVlan(userIp,_vlanDao.findById(userIp.getVlanId()));
      publicIps.add(publicIp);
    }
  }
  if (checkStaticNatIPAssocRequired(network,false,forRevoke,publicIps)) {
    applyIpAssociations(network,false,continueOnError,publicIps);
  }
  StaticNatServiceProvider element=_networkMgr.getStaticNatProviderForNetwork(network);
  try {
    success=element.applyStaticNats(network,staticNats);
  }
 catch (  ResourceUnavailableException e) {
    if (!continueOnError) {
      throw e;
    }
    s_logger.warn("String_Node_Str" + element.getName() + "String_Node_Str",e);
    success=false;
  }
  for (  StaticNat staticNat : staticNats) {
    if (staticNat.isForRevoke()) {
      for (      PublicIp publicIp : publicIps) {
        if (publicIp.getId() == staticNat.getSourceIpAddressId()) {
          publicIps.remove(publicIp);
          IPAddressVO ip=_ipAddressDao.findByIdIncludingRemoved(staticNat.getSourceIpAddressId());
          ip.setAssociatedWithVmId(null);
          publicIp=PublicIp.createFromAddrAndVlan(ip,_vlanDao.findById(ip.getVlanId()));
          publicIps.add(publicIp);
          break;
        }
      }
    }
  }
  if (checkStaticNatIPAssocRequired(network,true,forRevoke,publicIps)) {
    applyIpAssociations(network,true,continueOnError,publicIps);
  }
  return success;
}