From f4a96d4c853bd4f60539b9b9e9218b42640652a9 Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Mon, 3 Feb 2014 17:59:58 +0530 Subject: [PATCH] CLOUDSTACK-6011 . When detach is called on a deleted volume, avoid the NPE and throw an appropriate exception instead --- server/src/com/cloud/storage/VolumeApiServiceImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index c856379b812..69558250da3 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1382,6 +1382,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic volume = _volsDao.findByInstanceAndDeviceId(cmmd.getVirtualMachineId(), cmmd.getDeviceId()).get(0); } + // Check that the volume ID is valid + if (volume == null) { + throw new InvalidParameterValueException("Unable to find volume with ID: " + volumeId); + } + Long vmId = null; if (cmmd.getVirtualMachineId() == null) { @@ -1390,11 +1395,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic vmId = cmmd.getVirtualMachineId(); } - // Check that the volume ID is valid - if (volume == null) { - throw new InvalidParameterValueException("Unable to find volume with ID: " + volumeId); - } - // Permissions check _accountMgr.checkAccess(caller, null, true, volume);