Program: 106389
Project: 106389
Buggy source:
@Override public Pair<List<? extends Host>,List<? extends Host>> listHostsForMigrationOfVM(Long vmId,Long startIndex,Long pageSize){
  Account caller=UserContext.current().getCaller();
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    throw new PermissionDeniedException("String_Node_Str");
  }
  VMInstanceVO vm=_vmInstanceDao.findById(vmId);
  if (vm == null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (vm.getState() != State.Running) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM)&& !vm.getHypervisorType().equals(HypervisorType.Ovm)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(vm + "String_Node_Str");
    }
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ServiceOfferingVO svcOffering=_offeringsDao.findById(vm.getServiceOfferingId());
  if (svcOffering.getUseLocalStorage()) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(vm + "String_Node_Str");
    }
    throw new InvalidParameterValueException("String_Node_Str");
  }
  long srcHostId=vm.getHostId();
  Host srcHost=_hostDao.findById(srcHostId);
  if (srcHost == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + srcHostId + "String_Node_Str"+ vm);
    }
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(srcHost,srcHostId,"String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  Long cluster=srcHost.getClusterId();
  Type hostType=srcHost.getType();
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + cluster + "String_Node_Str"+ vm);
  }
  List<? extends Host> allHostsInCluster=searchForServers(startIndex,pageSize,null,hostType,null,null,null,cluster,null,null,null,null);
  allHostsInCluster.remove(srcHost);
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + allHostsInCluster);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + cluster + "String_Node_Str");
  }
  List<Host> suitableHosts=new ArrayList<Host>();
  Enumeration<HostAllocator> enHost=_hostAllocators.enumeration();
  VirtualMachineProfile<VMInstanceVO> vmProfile=new VirtualMachineProfileImpl<VMInstanceVO>(vm);
  DataCenterDeployment plan=new DataCenterDeployment(srcHost.getDataCenterId(),srcHost.getPodId(),srcHost.getClusterId(),null,null,null);
  ExcludeList excludes=new ExcludeList();
  excludes.addHost(srcHostId);
  while (enHost.hasMoreElements()) {
    final HostAllocator allocator=enHost.nextElement();
    suitableHosts=allocator.allocateTo(vmProfile,plan,Host.Type.Routing,excludes,HostAllocator.RETURN_UPTO_ALL,false);
    if (suitableHosts != null && !suitableHosts.isEmpty()) {
      break;
    }
  }
  if (suitableHosts.isEmpty()) {
    s_logger.debug("String_Node_Str");
  }
 else {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + suitableHosts);
    }
  }
  return new Pair<List<? extends Host>,List<? extends Host>>(allHostsInCluster,suitableHosts);
}

Fixed version (ground truth):
@Override public Pair<Pair<List<? extends Host>,Integer>,List<? extends Host>> listHostsForMigrationOfVM(Long vmId,Long startIndex,Long pageSize){
  Account caller=UserContext.current().getCaller();
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    throw new PermissionDeniedException("String_Node_Str");
  }
  VMInstanceVO vm=_vmInstanceDao.findById(vmId);
  if (vm == null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (vm.getState() != State.Running) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM)&& !vm.getHypervisorType().equals(HypervisorType.Ovm)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(vm + "String_Node_Str");
    }
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ServiceOfferingVO svcOffering=_offeringsDao.findById(vm.getServiceOfferingId());
  if (svcOffering.getUseLocalStorage()) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(vm + "String_Node_Str");
    }
    throw new InvalidParameterValueException("String_Node_Str");
  }
  long srcHostId=vm.getHostId();
  Host srcHost=_hostDao.findById(srcHostId);
  if (srcHost == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + srcHostId + "String_Node_Str"+ vm);
    }
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(srcHost,srcHostId,"String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  Long cluster=srcHost.getClusterId();
  Type hostType=srcHost.getType();
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + cluster + "String_Node_Str"+ vm);
  }
  Pair<List<HostVO>,Integer> allHostsInClusterPair=searchForServers(startIndex,pageSize,null,hostType,null,null,null,cluster,null,null,null,null);
  List<HostVO> allHostsInCluster=allHostsInClusterPair.first();
  allHostsInCluster.remove(srcHost);
  Pair<List<? extends Host>,Integer> otherHostsInCluster=new Pair<List<? extends Host>,Integer>(allHostsInCluster,new Integer(allHostsInClusterPair.second().intValue() - 1));
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + allHostsInCluster);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + cluster + "String_Node_Str");
  }
  List<Host> suitableHosts=new ArrayList<Host>();
  Enumeration<HostAllocator> enHost=_hostAllocators.enumeration();
  VirtualMachineProfile<VMInstanceVO> vmProfile=new VirtualMachineProfileImpl<VMInstanceVO>(vm);
  DataCenterDeployment plan=new DataCenterDeployment(srcHost.getDataCenterId(),srcHost.getPodId(),srcHost.getClusterId(),null,null,null);
  ExcludeList excludes=new ExcludeList();
  excludes.addHost(srcHostId);
  while (enHost.hasMoreElements()) {
    final HostAllocator allocator=enHost.nextElement();
    suitableHosts=allocator.allocateTo(vmProfile,plan,Host.Type.Routing,excludes,HostAllocator.RETURN_UPTO_ALL,false);
    if (suitableHosts != null && !suitableHosts.isEmpty()) {
      break;
    }
  }
  if (suitableHosts.isEmpty()) {
    s_logger.debug("String_Node_Str");
  }
 else {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + suitableHosts);
    }
  }
  return new Pair<Pair<List<? extends Host>,Integer>,List<? extends Host>>(otherHostsInCluster,suitableHosts);
}