Program: 105698
Project: 105698
Buggy source:
@Override @DB public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, CloudRuntimeException {
  final Long vmId=cmd.getId();
  Account caller=CallContext.current().getCallingAccount();
  final UserVmVO vm=_vmDao.findById(vmId.longValue());
  if (vm == null) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  _accountMgr.checkAccess(caller,null,true,vm);
  if (vm.getRemoved() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmId);
    }
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  if (vm.getState() != State.Destroyed) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmId);
    }
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vmId);
  }
  Transaction.execute(new TransactionCallbackWithExceptionNoReturn<ResourceAllocationException>(){
    @Override public void doInTransactionWithoutResult(    TransactionStatus status) throws ResourceAllocationException {
      Account account=_accountDao.lockRow(vm.getAccountId(),true);
      if (account.getRemoved() != null) {
        throw new CloudRuntimeException("String_Node_Str");
      }
      ServiceOfferingVO serviceOffering=_serviceOfferingDao.findById(vm.getId(),vm.getServiceOfferingId());
      resourceLimitCheck(account,vm.isDisplayVm(),new Long(serviceOffering.getCpu()),new Long(serviceOffering.getRamSize()));
      _haMgr.cancelDestroy(vm,vm.getHostId());
      try {
        if (!_itMgr.stateTransitTo(vm,VirtualMachine.Event.RecoveryRequested,null)) {
          s_logger.debug("String_Node_Str" + vmId);
          throw new InvalidParameterValueException("String_Node_Str" + vmId);
        }
      }
 catch (      NoTransitionException e) {
        throw new InvalidParameterValueException("String_Node_Str" + vmId);
      }
      List<VolumeVO> volumes=_volsDao.findByInstance(vmId);
      for (      VolumeVO volume : volumes) {
        if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
          Long templateId=volume.getTemplateId();
          Long diskOfferingId=volume.getDiskOfferingId();
          Long offeringId=null;
          if (diskOfferingId != null) {
            DiskOfferingVO offering=_diskOfferingDao.findById(diskOfferingId);
            if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) {
              offeringId=offering.getId();
            }
          }
          UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName(),offeringId,templateId,volume.getSize(),Volume.class.getName(),volume.getUuid(),volume.isDisplayVolume());
        }
      }
      resourceCountIncrement(account.getId(),vm.isDisplayVm(),new Long(serviceOffering.getCpu()),new Long(serviceOffering.getRamSize()));
    }
  }
);
  return _vmDao.findById(vmId);
}

Fixed version (ground truth):
@Override @DB public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, CloudRuntimeException {
  final Long vmId=cmd.getId();
  Account caller=CallContext.current().getCallingAccount();
  final UserVmVO vm=_vmDao.findById(vmId);
  if (vm == null) {
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  _accountMgr.checkAccess(caller,null,true,vm);
  if (vm.getRemoved() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmId);
    }
    throw new InvalidParameterValueException("String_Node_Str" + vmId);
  }
  if (vm.getState() != State.Destroyed) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vmId);
    }
    throw new InvalidParameterValueException("String_Node_Str" + vmId + "String_Node_Str");
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vmId);
  }
  Transaction.execute(new TransactionCallbackWithExceptionNoReturn<ResourceAllocationException>(){
    @Override public void doInTransactionWithoutResult(    TransactionStatus status) throws ResourceAllocationException {
      Account account=_accountDao.lockRow(vm.getAccountId(),true);
      if (account.getRemoved() != null) {
        throw new CloudRuntimeException("String_Node_Str");
      }
      ServiceOfferingVO serviceOffering=_serviceOfferingDao.findById(vm.getId(),vm.getServiceOfferingId());
      resourceLimitCheck(account,vm.isDisplayVm(),new Long(serviceOffering.getCpu()),new Long(serviceOffering.getRamSize()));
      _haMgr.cancelDestroy(vm,vm.getHostId());
      try {
        if (!_itMgr.stateTransitTo(vm,VirtualMachine.Event.RecoveryRequested,null)) {
          s_logger.debug("String_Node_Str" + vmId);
          throw new InvalidParameterValueException("String_Node_Str" + vmId);
        }
      }
 catch (      NoTransitionException e) {
        throw new InvalidParameterValueException("String_Node_Str" + vmId);
      }
      List<VolumeVO> volumes=_volsDao.findByInstance(vmId);
      for (      VolumeVO volume : volumes) {
        if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
          Long templateId=volume.getTemplateId();
          Long diskOfferingId=volume.getDiskOfferingId();
          Long offeringId=null;
          if (diskOfferingId != null) {
            DiskOfferingVO offering=_diskOfferingDao.findById(diskOfferingId);
            if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) {
              offeringId=offering.getId();
            }
          }
          UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName(),offeringId,templateId,volume.getSize(),Volume.class.getName(),volume.getUuid(),volume.isDisplayVolume());
        }
      }
      resourceCountIncrement(account.getId(),vm.isDisplayVm(),new Long(serviceOffering.getCpu()),new Long(serviceOffering.getRamSize()));
    }
  }
);
  return _vmDao.findById(vmId);
}