CLOUDSTACK-6011 . When detach is called on a deleted volume, avoid the NPE and 
throw an appropriate exception instead

(cherry picked from commit f4a96d4c853bd4f60539b9b9e9218b42640652a9)
Signed-off-by: Rohit Yadav <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e2fd4ef4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e2fd4ef4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e2fd4ef4

Branch: refs/heads/4.3
Commit: e2fd4ef42c92f64353b2830f5f19e5b32eafd3fa
Parents: d9e9471
Author: Likitha Shetty <[email protected]>
Authored: Mon Feb 3 17:59:58 2014 +0530
Committer: Rohit Yadav <[email protected]>
Committed: Fri Nov 14 17:32:41 2014 +0530

----------------------------------------------------------------------
 server/src/com/cloud/storage/VolumeApiServiceImpl.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e2fd4ef4/server/src/com/cloud/storage/VolumeApiServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java 
b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
index bc319b9..df5e205 100644
--- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java
@@ -1387,6 +1387,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) {
@@ -1395,11 +1400,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);
 

Reply via email to