Program: 106527
Project: 106527
Buggy source:
@Override public boolean applyStaticNats(Network network,List<? extends StaticNat> rules,List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
  if (routers == null || routers.isEmpty()) {
    s_logger.warn("String_Node_Str" + network.getId());
    throw new ResourceUnavailableException("String_Node_Str",DataCenter.class,network.getDataCenterId());
  }
  List<VirtualRouter> connectedRouters=new ArrayList<VirtualRouter>();
  List<VirtualRouter> disconnectedRouters=new ArrayList<VirtualRouter>();
  boolean result=true;
  String msg="String_Node_Str";
  for (  VirtualRouter router : routers) {
    if (router.getState() == State.Running) {
      s_logger.debug("String_Node_Str" + rules.size() + "String_Node_Str"+ network);
      if (router.isStopPending()) {
        if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
          throw new ResourceUnavailableException("String_Node_Str" + router.getInstanceName() + "String_Node_Str",VirtualRouter.class,router.getId());
        }
        s_logger.debug("String_Node_Str" + router.getInstanceName() + "String_Node_Str");
        continue;
      }
      try {
        result=applyStaticNat(router,rules);
        connectedRouters.add(router);
      }
 catch (      AgentUnavailableException e) {
        s_logger.warn(msg + router.getInstanceName(),e);
        disconnectedRouters.add(router);
      }
      if (!result) {
        throw new ResourceUnavailableException("String_Node_Str",VirtualRouter.class,router.getId());
      }
    }
 else     if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
      s_logger.debug("String_Node_Str" + router.getInstanceName() + "String_Node_Str"+ router.getState()+ "String_Node_Str");
    }
 else {
      s_logger.warn("String_Node_Str" + router.getState());
      throw new ResourceUnavailableException("String_Node_Str",VirtualRouter.class,router.getId());
    }
  }
  if (!connectedRouters.isEmpty()) {
    handleSingleWorkingRedundantRouter(connectedRouters,disconnectedRouters,msg);
  }
 else   if (!disconnectedRouters.isEmpty()) {
    for (    VirtualRouter router : disconnectedRouters) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(msg + router.getInstanceName() + "String_Node_Str"+ router.getId()+ "String_Node_Str");
      }
    }
    throw new ResourceUnavailableException(msg,VirtualRouter.class,disconnectedRouters.get(0).getId());
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean applyStaticNats(Network network,List<? extends StaticNat> rules,List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
  if (routers == null || routers.isEmpty()) {
    s_logger.warn("String_Node_Str" + network.getId());
    throw new ResourceUnavailableException("String_Node_Str",DataCenter.class,network.getDataCenterId());
  }
  List<VirtualRouter> connectedRouters=new ArrayList<VirtualRouter>();
  List<VirtualRouter> disconnectedRouters=new ArrayList<VirtualRouter>();
  boolean result=true;
  String msg="String_Node_Str";
  for (  VirtualRouter router : routers) {
    if (router.getState() == State.Running) {
      s_logger.debug("String_Node_Str" + rules.size() + "String_Node_Str"+ network);
      if (router.isStopPending()) {
        if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
          throw new ResourceUnavailableException("String_Node_Str" + router.getInstanceName() + "String_Node_Str",DataCenter.class,router.getDataCenterIdToDeployIn());
        }
        s_logger.debug("String_Node_Str" + router.getInstanceName() + "String_Node_Str");
        continue;
      }
      try {
        result=applyStaticNat(router,rules);
        connectedRouters.add(router);
      }
 catch (      AgentUnavailableException e) {
        s_logger.warn(msg + router.getInstanceName(),e);
        disconnectedRouters.add(router);
      }
      if (!result) {
        throw new ResourceUnavailableException("String_Node_Str",DataCenter.class,router.getDataCenterIdToDeployIn());
      }
    }
 else     if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
      s_logger.debug("String_Node_Str" + router.getInstanceName() + "String_Node_Str"+ router.getState()+ "String_Node_Str");
    }
 else {
      s_logger.warn("String_Node_Str" + router.getState());
      throw new ResourceUnavailableException("String_Node_Str",DataCenter.class,router.getDataCenterIdToDeployIn());
    }
  }
  if (!connectedRouters.isEmpty()) {
    handleSingleWorkingRedundantRouter(connectedRouters,disconnectedRouters,msg);
  }
 else   if (!disconnectedRouters.isEmpty()) {
    for (    VirtualRouter router : disconnectedRouters) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(msg + router.getInstanceName() + "String_Node_Str"+ router.getId()+ "String_Node_Str");
      }
    }
    throw new ResourceUnavailableException(msg,DataCenter.class,disconnectedRouters.get(0).getDataCenterIdToDeployIn());
  }
  return true;
}