Program: 105129
Project: 105129
Buggy source:
@Override public VMSnapshot allocVMSnapshot(Long vmId,String vsDisplayName,String vsDescription,Boolean snapshotMemory) throws ResourceAllocationException {
  Account caller=getCaller();
  UserVmVO userVmVo=_userVMDao.findById(vmId);
  if (userVmVo == null) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (_snapshotDao.listByInstanceId(vmId,Snapshot.State.BackedUp).size() > 0) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (snapshotMemory && _serviceOfferingDetailsDao.findDetail(userVmVo.getServiceOfferingId(),GPU.Keys.vgpuType.toString()) != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!_hypervisorCapabilitiesDao.isVmSnapshotEnabled(userVmVo.getHypervisorType(),"String_Node_Str"))   throw new InvalidParameterValueException("String_Node_Str" + userVmVo.getHypervisorType());
  if (vsDisplayName != null && vsDisplayName.length() > 255)   throw new InvalidParameterValueException("String_Node_Str");
  if (vsDescription != null && vsDescription.length() > 255)   throw new InvalidParameterValueException("String_Node_Str");
  String timeString=DateUtil.getDateDisplayString(DateUtil.GMT_TIMEZONE,new Date(),DateUtil.YYYYMMDD_FORMAT);
  String vmSnapshotName=userVmVo.getInstanceName() + "String_Node_Str" + timeString;
  if (vsDisplayName == null) {
    vsDisplayName=vmSnapshotName;
  }
  if (_vmSnapshotDao.findByName(vmId,vsDisplayName) != null) {
    throw new InvalidParameterValueException("String_Node_Str" + vsDisplayName + "String_Node_Str");
  }
  if (userVmVo.getState() != VirtualMachine.State.Running && userVmVo.getState() != VirtualMachine.State.Stopped) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (snapshotMemory && userVmVo.getState() == VirtualMachine.State.Stopped) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (userVmVo.getHypervisorType() == HypervisorType.KVM && userVmVo.getState() == State.Running && !snapshotMemory) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  _accountMgr.checkAccess(caller,null,true,userVmVo);
  if (_vmSnapshotDao.findByVm(vmId).size() >= _vmSnapshotMax) {
    throw new CloudRuntimeException("String_Node_Str" + _vmSnapshotMax + "String_Node_Str");
  }
  List<VolumeVO> listVolumes=_volumeDao.findByInstance(vmId);
  for (  VolumeVO volume : listVolumes) {
    List<SnapshotVO> activeSnapshots=_snapshotDao.listByInstanceId(volume.getInstanceId(),Snapshot.State.Creating,Snapshot.State.CreatedOnPrimary,Snapshot.State.BackingUp);
    if (activeSnapshots.size() > 0) {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
  if (hasActiveVMSnapshotTasks(vmId)) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  VMSnapshot.Type vmSnapshotType=VMSnapshot.Type.Disk;
  if (snapshotMemory && userVmVo.getState() == VirtualMachine.State.Running)   vmSnapshotType=VMSnapshot.Type.DiskAndMemory;
  try {
    VMSnapshotVO vmSnapshotVo=new VMSnapshotVO(userVmVo.getAccountId(),userVmVo.getDomainId(),vmId,vsDescription,vmSnapshotName,vsDisplayName,userVmVo.getServiceOfferingId(),vmSnapshotType,null);
    VMSnapshot vmSnapshot=_vmSnapshotDao.persist(vmSnapshotVo);
    if (vmSnapshot == null) {
      throw new CloudRuntimeException("String_Node_Str" + vmId);
    }
    return vmSnapshot;
  }
 catch (  Exception e) {
    String msg=e.getMessage();
    s_logger.error("String_Node_Str" + vmId + "String_Node_Str"+ msg);
  }
  return null;
}

Fixed version (ground truth):
@Override public VMSnapshot allocVMSnapshot(Long vmId,String vsDisplayName,String vsDescription,Boolean snapshotMemory) throws ResourceAllocationException {
  Account caller=getCaller();
  UserVmVO userVmVo=_userVMDao.findById(vmId);
  if (userVmVo == null) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (snapshotMemory && _serviceOfferingDetailsDao.findDetail(userVmVo.getServiceOfferingId(),GPU.Keys.vgpuType.toString()) != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!_hypervisorCapabilitiesDao.isVmSnapshotEnabled(userVmVo.getHypervisorType(),"String_Node_Str"))   throw new InvalidParameterValueException("String_Node_Str" + userVmVo.getHypervisorType());
  if (vsDisplayName != null && vsDisplayName.length() > 255)   throw new InvalidParameterValueException("String_Node_Str");
  if (vsDescription != null && vsDescription.length() > 255)   throw new InvalidParameterValueException("String_Node_Str");
  String timeString=DateUtil.getDateDisplayString(DateUtil.GMT_TIMEZONE,new Date(),DateUtil.YYYYMMDD_FORMAT);
  String vmSnapshotName=userVmVo.getInstanceName() + "String_Node_Str" + timeString;
  if (vsDisplayName == null) {
    vsDisplayName=vmSnapshotName;
  }
  if (_vmSnapshotDao.findByName(vmId,vsDisplayName) != null) {
    throw new InvalidParameterValueException("String_Node_Str" + vsDisplayName + "String_Node_Str");
  }
  if (userVmVo.getState() != VirtualMachine.State.Running && userVmVo.getState() != VirtualMachine.State.Stopped) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (snapshotMemory && userVmVo.getState() == VirtualMachine.State.Stopped) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (userVmVo.getHypervisorType() == HypervisorType.KVM && userVmVo.getState() == State.Running && !snapshotMemory) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  _accountMgr.checkAccess(caller,null,true,userVmVo);
  if (_vmSnapshotDao.findByVm(vmId).size() >= _vmSnapshotMax) {
    throw new CloudRuntimeException("String_Node_Str" + _vmSnapshotMax + "String_Node_Str");
  }
  List<VolumeVO> listVolumes=_volumeDao.findByInstance(vmId);
  for (  VolumeVO volume : listVolumes) {
    List<SnapshotVO> activeSnapshots=_snapshotDao.listByInstanceId(volume.getInstanceId(),Snapshot.State.Creating,Snapshot.State.CreatedOnPrimary,Snapshot.State.BackingUp);
    if (activeSnapshots.size() > 0) {
      throw new CloudRuntimeException("String_Node_Str");
    }
  }
  if (hasActiveVMSnapshotTasks(vmId)) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  VMSnapshot.Type vmSnapshotType=VMSnapshot.Type.Disk;
  if (snapshotMemory && userVmVo.getState() == VirtualMachine.State.Running)   vmSnapshotType=VMSnapshot.Type.DiskAndMemory;
  try {
    VMSnapshotVO vmSnapshotVo=new VMSnapshotVO(userVmVo.getAccountId(),userVmVo.getDomainId(),vmId,vsDescription,vmSnapshotName,vsDisplayName,userVmVo.getServiceOfferingId(),vmSnapshotType,null);
    VMSnapshot vmSnapshot=_vmSnapshotDao.persist(vmSnapshotVo);
    if (vmSnapshot == null) {
      throw new CloudRuntimeException("String_Node_Str" + vmId);
    }
    return vmSnapshot;
  }
 catch (  Exception e) {
    String msg=e.getMessage();
    s_logger.error("String_Node_Str" + vmId + "String_Node_Str"+ msg);
  }
  return null;
}