Program: 89189
Project: 89189
Buggy source:
protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache,final StartupCommand[] cmd,boolean forRebalance) throws ConnectionException {
  long hostId=attache.getId();
  HostVO host=_hostDao.findById(hostId);
  for (  Pair<Integer,Listener> monitor : _hostMonitors) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + monitor.second().getClass().getSimpleName());
    }
    for (int i=0; i < cmd.length; i++) {
      try {
        monitor.second().processConnect(host,cmd[i],forRebalance);
      }
 catch (      Exception e) {
        if (e instanceof ConnectionException) {
          ConnectionException ce=(ConnectionException)e;
          if (ce.isSetupError()) {
            s_logger.warn("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage());
            handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
            throw ce;
          }
 else {
            s_logger.info("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage());
            handleDisconnectWithoutInvestigation(attache,Event.ShutdownRequested);
            return attache;
          }
        }
 else         if (e instanceof HypervisorVersionChangedException) {
          handleDisconnectWithoutInvestigation(attache,Event.ShutdownRequested);
          throw new CloudRuntimeException("String_Node_Str" + attache.getId(),e);
        }
 else {
          s_logger.error("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage(),e);
          handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
          throw new CloudRuntimeException("String_Node_Str" + attache.getId(),e);
        }
      }
    }
  }
  Long dcId=host.getDataCenterId();
  ReadyCommand ready=new ReadyCommand(dcId);
  Answer answer=easySend(hostId,ready);
  if (answer == null || !answer.getResult()) {
    handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
    throw new CloudRuntimeException("String_Node_Str" + attache.getId());
  }
  agentStatusTransitTo(host,Event.Ready,_nodeId);
  attache.ready();
  return attache;
}

Fixed version (ground truth):
protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache,final StartupCommand[] cmd,boolean forRebalance) throws ConnectionException {
  long hostId=attache.getId();
  HostVO host=_hostDao.findById(hostId);
  for (  Pair<Integer,Listener> monitor : _hostMonitors) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + monitor.second().getClass().getSimpleName());
    }
    for (int i=0; i < cmd.length; i++) {
      try {
        monitor.second().processConnect(host,cmd[i],forRebalance);
      }
 catch (      Exception e) {
        if (e instanceof ConnectionException) {
          ConnectionException ce=(ConnectionException)e;
          if (ce.isSetupError()) {
            s_logger.warn("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage());
            handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
            throw ce;
          }
 else {
            s_logger.info("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage());
            handleDisconnectWithoutInvestigation(attache,Event.ShutdownRequested);
            return attache;
          }
        }
 else         if (e instanceof HypervisorVersionChangedException) {
          handleDisconnectWithoutInvestigation(attache,Event.ShutdownRequested);
          throw new CloudRuntimeException("String_Node_Str" + attache.getId(),e);
        }
 else {
          s_logger.error("String_Node_Str" + monitor.second().getClass().getSimpleName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ e.getMessage(),e);
          handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
          throw new CloudRuntimeException("String_Node_Str" + attache.getId(),e);
        }
      }
    }
  }
  Long dcId=host.getDataCenterId();
  ReadyCommand ready=new ReadyCommand(dcId);
  Answer answer=easySend(hostId,ready);
  if (answer == null || !answer.getResult()) {
    handleDisconnectWithoutInvestigation(attache,Event.AgentDisconnected);
  }
  agentStatusTransitTo(host,Event.Ready,_nodeId);
  attache.ready();
  return attache;
}