Program: 106897
Project: 106897
Buggy source:
private void scanDirectAgentToLoad(){
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
  long cutSeconds=(System.currentTimeMillis() >> 10) - (_pingInterval * 3);
  List<HostVO> hosts=_hostDao.findDirectAgentToLoad(cutSeconds,_loadSize);
  if (hosts != null && hosts.size() == _loadSize) {
    Long clusterId=hosts.get((int)(_loadSize - 1)).getClusterId();
    if (clusterId != null) {
      for (int i=(int)(_loadSize - 1); i > 0; i--) {
        if (hosts.get(i).getClusterId() == clusterId) {
          hosts.remove(i);
        }
 else {
          break;
        }
      }
    }
  }
  if (hosts != null && hosts.size() > 0) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str");
    for (    HostVO host : hosts) {
      try {
        AgentAttache agentattache=findAttache(host.getId());
        if (agentattache != null) {
          if (agentattache.forForward()) {
            if (s_logger.isInfoEnabled()) {
              s_logger.info(host + "String_Node_Str");
            }
            removeAgent(agentattache,Status.Disconnected);
          }
 else {
            continue;
          }
        }
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ host.getName()+ "String_Node_Str");
        }
        loadDirectlyConnectedHost(host,false);
      }
 catch (      Throwable e) {
        s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ host.getName()+ "String_Node_Str"+ e.toString());
      }
    }
  }
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
}

Fixed version (ground truth):
private void scanDirectAgentToLoad(){
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
  long cutSeconds=(System.currentTimeMillis() >> 10) - (_pingInterval * 3);
  List<HostVO> hosts=_hostDao.findDirectAgentToLoad(cutSeconds,_loadSize);
  if (hosts != null && hosts.size() == _loadSize) {
    if (hosts.size() > 1 && hosts.get(0).getClusterId().longValue() != hosts.get(hosts.size() - 1).getClusterId().longValue()) {
      Long clusterId=hosts.get((int)(_loadSize - 1)).getClusterId();
      if (clusterId != null) {
        for (int i=(int)(_loadSize - 1); i > 0; i--) {
          if (hosts.get(i).getClusterId().longValue() == clusterId.longValue()) {
            hosts.remove(i);
          }
 else {
            break;
          }
        }
      }
    }
  }
  if (hosts != null && hosts.size() > 0) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str");
    for (    HostVO host : hosts) {
      try {
        AgentAttache agentattache=findAttache(host.getId());
        if (agentattache != null) {
          if (agentattache.forForward()) {
            if (s_logger.isInfoEnabled()) {
              s_logger.info(host + "String_Node_Str");
            }
            removeAgent(agentattache,Status.Disconnected);
          }
 else {
            continue;
          }
        }
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ host.getName()+ "String_Node_Str");
        }
        loadDirectlyConnectedHost(host,false);
      }
 catch (      Throwable e) {
        s_logger.warn("String_Node_Str" + host.getId() + "String_Node_Str"+ host.getName()+ "String_Node_Str",e);
      }
    }
  }
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str");
  }
}