Juan Hernandez has uploaded a new change for review.

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

restapi: Avoid 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 an empty list in those cases.

Change-Id: Id17ef36193c21e113d4abafeee0c769a2a948bd3
Bug-Url: https://bugzilla.redhat.com/1150953
Signed-off-by: Juan Hernandez <[email protected]>
(cherry picked from commit f1dc8f77e611a2b8f40ddac822032632833d4eb0)
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractBackendReadOnlyDevicesResource.java
1 file changed, 8 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/45/34945/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..8654607 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
@@ -59,13 +59,15 @@
     protected C mapCollection(List<Q> entities, boolean addLinks) {
         C collection = instantiate(collectionType);
         List<D> list = getList(collection);
-        for (Q entity : entities) {
-            D candidate = populate(map(entity), entity);
-            if (validate(candidate)) {
-                if (addLinks) {
-                    candidate = addLinks(candidate);
+        if (entities != null) {
+            for (Q entity : entities) {
+                D candidate = populate(map(entity), entity);
+                if (validate(candidate)) {
+                    if (addLinks) {
+                        candidate = addLinks(candidate);
+                    }
+                    list.add(candidate);
                 }
-                list.add(candidate);
             }
         }
         return collection;


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

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

Reply via email to