Program: 106464
Project: 106464
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_VM_MIGRATE,eventDescription="String_Node_Str",async=true) public VirtualMachine migrateVirtualMachine(Long vmId,Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
  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) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  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=_serviceOfferingDao.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();
  if (destinationHost.getId() == srcHostId) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (destinationHost.getStatus() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
    throw new InvalidParameterValueException("String_Node_Str" + destinationHost.getStatus() + "String_Node_Str"+ destinationHost.getResourceState());
  }
  DataCenterVO dcVO=_dcDao.findById(destinationHost.getDataCenterId());
  HostPodVO pod=_podDao.findById(destinationHost.getPodId());
  Cluster cluster=_clusterDao.findById(destinationHost.getClusterId());
  DeployDestination dest=new DeployDestination(dcVO,pod,cluster,destinationHost);
  HypervisorType hypervisorType=destinationHost.getHypervisorType();
  String hypervisorVersion=destinationHost.getHypervisorVersion();
  Long maxGuestLimit=_hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType,hypervisorVersion);
  Long vmCount=_vmInstanceDao.countRunningByHostId(destinationHost.getId());
  if (vmCount.longValue() == maxGuestLimit.longValue()) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + destinationHost.getName() + "String_Node_Str"+ destinationHost.getId()+ "String_Node_Str"+ maxGuestLimit+ "String_Node_Str");
    }
    throw new VirtualMachineMigrationException("String_Node_Str" + destinationHost.getId() + "String_Node_Str"+ maxGuestLimit+ "String_Node_Str");
  }
  VMInstanceVO migratedVm=_itMgr.migrate(vm,srcHostId,dest);
  return migratedVm;
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_VM_MIGRATE,eventDescription="String_Node_Str",async=true) public VirtualMachine migrateVirtualMachine(Long vmId,Host destinationHost) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
  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) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  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=_serviceOfferingDao.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();
  if (destinationHost.getId() == srcHostId) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (destinationHost.getStatus() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
    throw new InvalidParameterValueException("String_Node_Str" + destinationHost.getStatus() + "String_Node_Str"+ destinationHost.getResourceState());
  }
  DataCenterVO dcVO=_dcDao.findById(destinationHost.getDataCenterId());
  HostPodVO pod=_podDao.findById(destinationHost.getPodId());
  Cluster cluster=_clusterDao.findById(destinationHost.getClusterId());
  DeployDestination dest=new DeployDestination(dcVO,pod,cluster,destinationHost);
  HostVO destinationHostVO=_hostDao.findById(destinationHost.getId());
  if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + destinationHost.getName() + "String_Node_Str"+ destinationHost.getId()+ "String_Node_Str");
    }
    throw new VirtualMachineMigrationException("String_Node_Str" + destinationHost.getId() + "String_Node_Str");
  }
  VMInstanceVO migratedVm=_itMgr.migrate(vm,srcHostId,dest);
  return migratedVm;
}