Program: 89540
Project: 89540
Buggy source:
@Override public void run(){
  try {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + _nodeId);
    }
    if (_agentToTransferIds.size() > 0) {
      s_logger.debug("String_Node_Str" + _agentToTransferIds.size() + "String_Node_Str");
      for (      Long hostId : _agentToTransferIds) {
        AgentAttache attache=findAttache(hostId);
        Date cutTime=DateUtil.currentGMTTime();
        if (_hostTransferDao.isNotActive(hostId,new Date(cutTime.getTime() - rebalanceTimeOut))) {
          s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
          failStartRebalance(hostId);
          return;
        }
        HostTransferMapVO transferMap=_hostTransferDao.findByIdAndCurrentOwnerId(hostId,_nodeId);
        if (transferMap == null) {
          s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
          failStartRebalance(hostId);
          return;
        }
        ManagementServerHostVO ms=_mshostDao.findByMsid(transferMap.getFutureOwner());
        if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
          s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ ms+ "String_Node_Str");
          failStartRebalance(hostId);
          return;
        }
        if (attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
          rebalanceHost(hostId,transferMap.getInitialOwner(),transferMap.getFutureOwner());
        }
 else {
          s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ attache.getQueueSize()+ "String_Node_Str"+ attache.getNonRecurringListenersSize());
        }
      }
    }
 else {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("String_Node_Str" + _nodeId);
      }
    }
  }
 catch (  Throwable e) {
    s_logger.error("String_Node_Str",e);
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + _nodeId);
    }
synchronized (_agentToTransferIds) {
      if (_agentToTransferIds.size() > 0) {
        s_logger.debug("String_Node_Str" + _agentToTransferIds.size() + "String_Node_Str");
        for (Iterator<Long> iterator=_agentToTransferIds.iterator(); iterator.hasNext(); ) {
          Long hostId=iterator.next();
          AgentAttache attache=findAttache(hostId);
          Date cutTime=DateUtil.currentGMTTime();
          if (_hostTransferDao.isNotActive(hostId,new Date(cutTime.getTime() - rebalanceTimeOut))) {
            s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
            iterator.remove();
            _hostTransferDao.completeAgentTransfer(hostId);
            continue;
          }
          HostTransferMapVO transferMap=_hostTransferDao.findByIdAndCurrentOwnerId(hostId,_nodeId);
          if (transferMap == null) {
            s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
            iterator.remove();
            _hostTransferDao.completeAgentTransfer(hostId);
            continue;
          }
          ManagementServerHostVO ms=_mshostDao.findByMsid(transferMap.getFutureOwner());
          if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
            s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ ms+ "String_Node_Str");
            iterator.remove();
            _hostTransferDao.completeAgentTransfer(hostId);
            continue;
          }
          if (attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
            iterator.remove();
            rebalanceHost(hostId,transferMap.getInitialOwner(),transferMap.getFutureOwner());
          }
 else {
            s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ attache.getQueueSize()+ "String_Node_Str"+ attache.getNonRecurringListenersSize());
          }
        }
      }
 else {
        if (s_logger.isTraceEnabled()) {
          s_logger.trace("String_Node_Str" + _nodeId);
        }
      }
    }
  }
 catch (  Throwable e) {
    s_logger.error("String_Node_Str",e);
  }
}