Program: 89241
Project: 89241
Buggy source:
@DB private boolean doDeleteHost(long hostId,boolean isForced,boolean isForceDeleteStorage){
  User caller=_accountMgr.getActiveUser(UserContext.current().getCallerUserId());
  HostVO host=_hostDao.findById(hostId);
  if (host == null) {
    throw new InvalidParameterValueException("String_Node_Str" + hostId + "String_Node_Str");
  }
  _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(),host.getDataCenterId());
  AgentAttache attache=_agentMgr.findAttache(hostId);
  List<StoragePoolHostVO> pools=_storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
  ResourceStateAdapter.DeleteHostAnswer answer=(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST,false,host,new Boolean(isForced),new Boolean(isForceDeleteStorage));
  if (answer == null) {
    throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ host.getHypervisorType()+ "String_Node_Str"+ host.getType());
  }
  if (answer.getIsException()) {
    return false;
  }
  if (!answer.getIsContinue()) {
    return true;
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(),host.getDataCenterId(),null);
  _agentMgr.disconnectWithoutInvestigation(hostId,Status.Event.Remove);
  _hostDetailsDao.deleteDetails(hostId);
  host.setGuid(null);
  Long clusterId=host.getClusterId();
  host.setClusterId(null);
  _hostDao.update(host.getId(),host);
  _hostDao.remove(hostId);
  if (clusterId != null) {
    List<HostVO> hosts=listAllHostsInCluster(clusterId);
    if (hosts.size() == 0) {
      ClusterVO cluster=_clusterDao.findById(clusterId);
      cluster.setGuid(null);
      _clusterDao.update(clusterId,cluster);
    }
  }
  try {
    resourceStateTransitTo(host,ResourceState.Event.DeleteHost,_nodeId);
  }
 catch (  NoTransitionException e) {
    s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
  }
  _storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
  for (  StoragePoolHostVO pool : pools) {
    Long poolId=pool.getPoolId();
    StoragePoolVO storagePool=_storagePoolDao.findById(poolId);
    if (storagePool.isLocal() && isForceDeleteStorage) {
      storagePool.setUuid(null);
      storagePool.setClusterId(null);
      _storagePoolDao.update(poolId,storagePool);
      _storagePoolDao.remove(poolId);
      s_logger.debug("String_Node_Str" + poolId + "String_Node_Str"+ hostId);
    }
  }
  Object[] capacityTypes={Capacity.CAPACITY_TYPE_CPU,Capacity.CAPACITY_TYPE_MEMORY};
  SearchCriteria<CapacityVO> hostCapacitySC=_capacityDao.createSearchCriteria();
  hostCapacitySC.addAnd("String_Node_Str",SearchCriteria.Op.EQ,hostId);
  hostCapacitySC.addAnd("String_Node_Str",SearchCriteria.Op.IN,capacityTypes);
  _capacityDao.remove(hostCapacitySC);
  txn.commit();
  return true;
}

Fixed version (ground truth):
@DB protected boolean doDeleteHost(long hostId,boolean isForced,boolean isForceDeleteStorage){
  User caller=_accountMgr.getActiveUser(UserContext.current().getCallerUserId());
  HostVO host=_hostDao.findById(hostId);
  if (host == null) {
    throw new InvalidParameterValueException("String_Node_Str" + hostId + "String_Node_Str");
  }
  _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(),host.getDataCenterId());
  AgentAttache attache=_agentMgr.findAttache(hostId);
  List<StoragePoolHostVO> pools=_storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
  ResourceStateAdapter.DeleteHostAnswer answer=(ResourceStateAdapter.DeleteHostAnswer)dispatchToStateAdapters(ResourceStateAdapter.Event.DELETE_HOST,false,host,new Boolean(isForced),new Boolean(isForceDeleteStorage));
  if (answer == null) {
    throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ hostId+ "String_Node_Str"+ host.getHypervisorType()+ "String_Node_Str"+ host.getType());
  }
  if (answer.getIsException()) {
    return false;
  }
  if (!answer.getIsContinue()) {
    return true;
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  _dcDao.releasePrivateIpAddress(host.getPrivateIpAddress(),host.getDataCenterId(),null);
  _agentMgr.disconnectWithoutInvestigation(hostId,Status.Event.Remove);
  _hostDetailsDao.deleteDetails(hostId);
  host.setGuid(null);
  Long clusterId=host.getClusterId();
  host.setClusterId(null);
  _hostDao.update(host.getId(),host);
  _hostDao.remove(hostId);
  if (clusterId != null) {
    List<HostVO> hosts=listAllHostsInCluster(clusterId);
    if (hosts.size() == 0) {
      ClusterVO cluster=_clusterDao.findById(clusterId);
      cluster.setGuid(null);
      _clusterDao.update(clusterId,cluster);
    }
  }
  try {
    resourceStateTransitTo(host,ResourceState.Event.DeleteHost,_nodeId);
  }
 catch (  NoTransitionException e) {
    s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
  }
  _storagePoolHostDao.deletePrimaryRecordsForHost(hostId);
  for (  StoragePoolHostVO pool : pools) {
    Long poolId=pool.getPoolId();
    StoragePoolVO storagePool=_storagePoolDao.findById(poolId);
    if (storagePool.isLocal() && isForceDeleteStorage) {
      storagePool.setUuid(null);
      storagePool.setClusterId(null);
      _storagePoolDao.update(poolId,storagePool);
      _storagePoolDao.remove(poolId);
      s_logger.debug("String_Node_Str" + poolId + "String_Node_Str"+ hostId);
    }
  }
  Object[] capacityTypes={Capacity.CAPACITY_TYPE_CPU,Capacity.CAPACITY_TYPE_MEMORY};
  SearchCriteria<CapacityVO> hostCapacitySC=_capacityDao.createSearchCriteria();
  hostCapacitySC.addAnd("String_Node_Str",SearchCriteria.Op.EQ,hostId);
  hostCapacitySC.addAnd("String_Node_Str",SearchCriteria.Op.IN,capacityTypes);
  _capacityDao.remove(hostCapacitySC);
  txn.commit();
  return true;
}