Program: 89147
Project: 89147
Buggy source:
@Override public boolean associateIP(Network network,List<? extends PublicIpAddress> ipAddress,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) {
      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;
      }
      Commands cmds=new Commands(OnError.Continue);
      createAssociateIPCommands(router,ipAddress,cmds,0);
      try {
        result=sendCommandsToRouter(router,cmds);
        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" + router.getState(),DataCenter.class,network.getDataCenterId());
    }
  }
  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 result;
}

Fixed version (ground truth):
@Override public boolean associateIP(Network network,List<? extends PublicIpAddress> ipAddress,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) {
      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;
      }
      Commands cmds=new Commands(OnError.Continue);
      createAssociateIPCommands(router,ipAddress,cmds,0);
      try {
        result=sendCommandsToRouter(router,cmds);
        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" + router.getState(),DataCenter.class,network.getDataCenterId());
    }
  }
  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 result;
}