Program: 105699
Project: 105699
Buggy source:
@Override @ActionEvent(eventType=EventTypes.EVENT_VM_MIGRATE,eventDescription="String_Node_Str",async=true) public VirtualMachine migrateVirtualMachineWithVolume(Long vmId,Host destinationHost,Map<String,String> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
  Account caller=CallContext.current().getCallingAccount();
  if (!_accountMgr.isRootAdmin(caller.getId())) {
    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);
    }
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str" + "String_Node_Str");
    ex.addProxyObject(vm.getUuid(),"String_Node_Str");
    throw ex;
  }
  if (serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(),GPU.Keys.pciDevice.toString()) != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM)&& !vm.getHypervisorType().equals(HypervisorType.Ovm)&& !vm.getHypervisorType().equals(HypervisorType.Hyperv)&& !vm.getHypervisorType().equals(HypervisorType.Simulator)) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  long srcHostId=vm.getHostId();
  Host srcHost=_resourceMgr.getHost(srcHostId);
  if (destinationHost.getId() == srcHostId) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  if (!(srcHost.getHypervisorType().equals(destinationHost.getHypervisorType()) && srcHost.getHypervisorVersion().equals(destinationHost.getHypervisorVersion()))) {
    throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + srcHost.getHypervisorType().toString() + "String_Node_Str"+ srcHost.getHypervisorVersion()+ "String_Node_Str"+ destinationHost.getHypervisorType().toString()+ "String_Node_Str"+ destinationHost.getHypervisorVersion());
  }
  HypervisorCapabilitiesVO capabilities=_hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(),srcHost.getHypervisorVersion());
  if (!capabilities.isStorageMotionSupported()) {
    throw new CloudRuntimeException("String_Node_Str" + srcHost.getHypervisorType() + "String_Node_Str"+ srcHost.getHypervisorVersion());
  }
  if (destinationHost.getState() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
    throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + destinationHost.getState() + "String_Node_Str"+ destinationHost.getResourceState());
  }
  List<VolumeVO> vmVolumes=_volsDao.findUsableVolumesForInstance(vm.getId());
  Map<Long,Long> volToPoolObjectMap=new HashMap<Long,Long>();
  if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) {
    if (volumeToPool.isEmpty()) {
      throw new InvalidParameterValueException("String_Node_Str" + vm + "String_Node_Str"+ srcHost+ "String_Node_Str"+ destinationHost+ "String_Node_Str");
    }
  }
  if (!volumeToPool.isEmpty()) {
    for (    Map.Entry<String,String> entry : volumeToPool.entrySet()) {
      VolumeVO volume=_volsDao.findByUuid(entry.getKey());
      StoragePoolVO pool=_storagePoolDao.findByUuid(entry.getValue());
      if (volume == null) {
        throw new InvalidParameterValueException("String_Node_Str" + entry.getKey());
      }
 else       if (pool == null) {
        throw new InvalidParameterValueException("String_Node_Str" + entry.getValue());
      }
 else {
        if (!vmVolumes.contains(volume)) {
          throw new InvalidParameterValueException("String_Node_Str" + volume + "String_Node_Str"+ "String_Node_Str"+ vm+ "String_Node_Str");
        }
        volToPoolObjectMap.put(Long.valueOf(volume.getId()),Long.valueOf(pool.getId()));
      }
    }
  }
  for (  VolumeVO volume : vmVolumes) {
    if (volume.getState() != Volume.State.Ready) {
      throw new CloudRuntimeException("String_Node_Str" + volume + "String_Node_Str"+ "String_Node_Str");
    }
  }
  HostVO destinationHostVO=_hostDao.findById(destinationHost.getId());
  if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
    throw new VirtualMachineMigrationException("String_Node_Str" + destinationHost.getName() + "String_Node_Str"+ destinationHost.getId()+ "String_Node_Str"+ "String_Node_Str");
  }
  checkHostsDedication(vm,srcHostId,destinationHost.getId());
  _itMgr.migrateWithStorage(vm.getUuid(),srcHostId,destinationHost.getId(),volToPoolObjectMap);
  return _vmDao.findById(vm.getId());
}

Fixed version (ground truth):
@Override @ActionEvent(eventType=EventTypes.EVENT_VM_MIGRATE,eventDescription="String_Node_Str",async=true) public VirtualMachine migrateVirtualMachineWithVolume(Long vmId,Host destinationHost,Map<String,String> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
  Account caller=CallContext.current().getCallingAccount();
  if (!_accountMgr.isRootAdmin(caller.getId())) {
    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);
    }
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str" + "String_Node_Str");
    ex.addProxyObject(vm.getUuid(),"String_Node_Str");
    throw ex;
  }
  if (serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(),GPU.Keys.pciDevice.toString()) != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM)&& !vm.getHypervisorType().equals(HypervisorType.Ovm)&& !vm.getHypervisorType().equals(HypervisorType.Hyperv)&& !vm.getHypervisorType().equals(HypervisorType.Simulator)) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  long srcHostId=vm.getHostId();
  Host srcHost=_resourceMgr.getHost(srcHostId);
  if (srcHost == null) {
    throw new InvalidParameterValueException("String_Node_Str" + srcHostId);
  }
  if (destinationHost.getId() == srcHostId) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
  }
  if (!(srcHost.getHypervisorType().equals(destinationHost.getHypervisorType()) && srcHost.getHypervisorVersion().equals(destinationHost.getHypervisorVersion()))) {
    throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + srcHost.getHypervisorType().toString() + "String_Node_Str"+ srcHost.getHypervisorVersion()+ "String_Node_Str"+ destinationHost.getHypervisorType().toString()+ "String_Node_Str"+ destinationHost.getHypervisorVersion());
  }
  HypervisorCapabilitiesVO capabilities=_hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(),srcHost.getHypervisorVersion());
  if (!capabilities.isStorageMotionSupported()) {
    throw new CloudRuntimeException("String_Node_Str" + srcHost.getHypervisorType() + "String_Node_Str"+ srcHost.getHypervisorVersion());
  }
  if (destinationHost.getState() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
    throw new CloudRuntimeException("String_Node_Str" + "String_Node_Str" + destinationHost.getState() + "String_Node_Str"+ destinationHost.getResourceState());
  }
  List<VolumeVO> vmVolumes=_volsDao.findUsableVolumesForInstance(vm.getId());
  Map<Long,Long> volToPoolObjectMap=new HashMap<Long,Long>();
  if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) {
    if (volumeToPool.isEmpty()) {
      throw new InvalidParameterValueException("String_Node_Str" + vm + "String_Node_Str"+ srcHost+ "String_Node_Str"+ destinationHost+ "String_Node_Str");
    }
  }
  if (!volumeToPool.isEmpty()) {
    for (    Map.Entry<String,String> entry : volumeToPool.entrySet()) {
      VolumeVO volume=_volsDao.findByUuid(entry.getKey());
      StoragePoolVO pool=_storagePoolDao.findByUuid(entry.getValue());
      if (volume == null) {
        throw new InvalidParameterValueException("String_Node_Str" + entry.getKey());
      }
 else       if (pool == null) {
        throw new InvalidParameterValueException("String_Node_Str" + entry.getValue());
      }
 else {
        if (!vmVolumes.contains(volume)) {
          throw new InvalidParameterValueException("String_Node_Str" + volume + "String_Node_Str"+ "String_Node_Str"+ vm+ "String_Node_Str");
        }
        volToPoolObjectMap.put(Long.valueOf(volume.getId()),Long.valueOf(pool.getId()));
      }
    }
  }
  for (  VolumeVO volume : vmVolumes) {
    if (volume.getState() != Volume.State.Ready) {
      throw new CloudRuntimeException("String_Node_Str" + volume + "String_Node_Str"+ "String_Node_Str");
    }
  }
  HostVO destinationHostVO=_hostDao.findById(destinationHost.getId());
  if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
    throw new VirtualMachineMigrationException("String_Node_Str" + destinationHost.getName() + "String_Node_Str"+ destinationHost.getId()+ "String_Node_Str"+ "String_Node_Str");
  }
  checkHostsDedication(vm,srcHostId,destinationHost.getId());
  _itMgr.migrateWithStorage(vm.getUuid(),srcHostId,destinationHost.getId(),volToPoolObjectMap);
  return _vmDao.findById(vm.getId());
}