Program: 106206
Project: 106206
Buggy source:
@Override public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException {
  Account caller=UserContext.current().getCaller();
  Long userId=UserContext.current().getCallerUserId();
  UserVmVO vm=_vmDao.findById(vmId);
  if (vm == null || vm.getRemoved() != null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (vm.getState() == State.Destroyed || vm.getState() == State.Expunging) {
    s_logger.trace("String_Node_Str" + vmId + "String_Node_Str");
    return vm;
  }
  _accountMgr.checkAccess(caller,null,true,vm);
  User userCaller=_userDao.findById(userId);
  boolean status;
  State vmState=vm.getState();
  try {
    VirtualMachineEntity vmEntity=_orchSrvc.getVirtualMachine(vm.getUuid());
    status=vmEntity.destroy(new Long(userId).toString());
  }
 catch (  CloudException e) {
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str",e);
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (status) {
    List<VolumeVO> volumes=_volsDao.findByInstance(vmId);
    for (    VolumeVO volume : volumes) {
      if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName(),Volume.class.getName(),volume.getUuid());
      }
    }
    if (vmState != State.Error) {
      ServiceOfferingVO offering=_serviceOfferingDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
      resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()),new Long(offering.getRamSize()));
    }
    return _vmDao.findById(vmId);
  }
 else {
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
}

Fixed version (ground truth):
@Override public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException {
  Account caller=UserContext.current().getCaller();
  Long userId=UserContext.current().getCallerUserId();
  UserVmVO vm=_vmDao.findById(vmId);
  if (vm == null || vm.getRemoved() != null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
    throw ex;
  }
  if (vm.getState() == State.Destroyed || vm.getState() == State.Expunging) {
    s_logger.trace("String_Node_Str" + vmId + "String_Node_Str");
    return vm;
  }
  _accountMgr.checkAccess(caller,null,true,vm);
  User userCaller=_userDao.findById(userId);
  boolean status;
  State vmState=vm.getState();
  try {
    VirtualMachineEntity vmEntity=_orchSrvc.getVirtualMachine(vm.getUuid());
    status=vmEntity.destroy(new Long(userId).toString());
  }
 catch (  CloudException e) {
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str",e);
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
  if (status) {
    List<VolumeVO> volumes=_volsDao.findByInstance(vmId);
    for (    VolumeVO volume : volumes) {
      if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName(),Volume.class.getName(),volume.getUuid());
      }
    }
    if (vmState != State.Error) {
      ServiceOfferingVO offering=_serviceOfferingDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
      resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()),new Long(offering.getRamSize()));
    }
    return _vmDao.findById(vmId);
  }
 else {
    CloudRuntimeException ex=new CloudRuntimeException("String_Node_Str");
    ex.addProxyObject(vm,vmId,"String_Node_Str");
    throw ex;
  }
}