Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Fix NPE in request for CDROMs of wrong VM
......................................................................

restapi: Fix NPE in request for CDROMs of wrong VM

Currently when we receive a request for the collection of CDROMs of a VM
we don't take into account that the query performed to find the VM can
return null if there isn't such a VM (the identifier is wrong, or the VM
has been removed). To avoid that NPE this patch checks the result of the
query and will respond with HTTP code 404 (not found) in those cases.

Change-Id: I55d4742649d8d260ae4d7c924c1a9b91efbcea6b
Bug-Url: https://bugzilla.redhat.com/1150953
Signed-off-by: Juan Hernandez <[email protected]>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
1 file changed, 10 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/33977/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
index 5a516bf..0a2f41c 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
@@ -3,6 +3,7 @@
 import java.lang.reflect.Method;
 import java.util.List;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
 import org.ovirt.engine.api.model.BaseDevice;
@@ -40,7 +41,15 @@
 
     @Override
     public C list() {
-        return mapCollection(getBackendCollection(queryType, queryParams));
+        // This query is loading the collection of containers of the devices, 
not the devices themselves. For example,
+        // when requesting the CDROMs of a VM this query will actually load a 
collection contain the VM, not the CDROMs.
+        // The result will be null if there is no such VM (if the user 
provided an incorrect id, or if the VM has been
+        // removed) and in that case we need to respond with the 404 error 
code.
+        List<Q> collection = getBackendCollection(queryType, queryParams);
+        if (collection == null || collection.isEmpty()) {
+            throw new WebApplicationException(Response.Status.NOT_FOUND);
+        }
+        return mapCollection(collection);
     }
 
     @Override


-- 
To view, visit http://gerrit.ovirt.org/33977
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55d4742649d8d260ae4d7c924c1a9b91efbcea6b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to