Martin Sivák has uploaded a new change for review.

Change subject: engine: Fix a possible NPE when the user removes stale policy 
unit
......................................................................

engine: Fix a possible NPE when the user removes stale policy unit

When the external scheduler is in use and some plugin disappears,
the plugin is still visible (in disabled form) in the Manage
Policy Units dialog. If the user tries to remove it it has to
work correctly and not raise NPE.

Change-Id: I5fa617af3363ec1d71cf8f0a25af43be4b141067
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1065914
Signed-off-by: Martin Sivak <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
1 file changed, 16 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/08/25308/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
index 7cbd4e6..838dd7f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
@@ -839,21 +839,33 @@
     /**
      * returns all cluster policies names containing the specific policy unit.
      * @param policyUnitId
-     * @return
+     * @return List of cluster policy names that use the referenced 
policyUnitId
+     *         or null if the policy unit is not available.
      */
     public List<String> getClusterPoliciesNamesByPolicyUnitId(Guid 
policyUnitId) {
         List<String> list = new ArrayList<String>();
-        PolicyUnit policyUnit = policyUnits.get(policyUnitId).getPolicyUnit();
+        final PolicyUnitImpl policyUnitImpl = policyUnits.get(policyUnitId);
+        if (policyUnitImpl == null) {
+            log.warnFormat("Trying to find usages of non-existing policy unit 
%s", policyUnitId.toString());
+            return null;
+        }
+
+        PolicyUnit policyUnit = policyUnitImpl.getPolicyUnit();
         if (policyUnit != null) {
             for (ClusterPolicy clusterPolicy : policyMap.values()) {
                 switch (policyUnit.getPolicyUnitType()) {
                 case Filter:
-                    if (clusterPolicy.getFilters().contains(policyUnitId)) {
+                    Collection<Guid> filters = clusterPolicy.getFilters();
+                    if (filters != null && filters.contains(policyUnitId)) {
                         list.add(clusterPolicy.getName());
                     }
                     break;
                 case Weight:
-                    for (Pair<Guid, Integer> pair : 
clusterPolicy.getFunctions()) {
+                    Collection<Pair<Guid, Integer>> functions = 
clusterPolicy.getFunctions();
+                    if (functions == null) {
+                        break;
+                    }
+                    for (Pair<Guid, Integer> pair : functions) {
                         if (pair.getFirst().equals(policyUnitId)) {
                             list.add(clusterPolicy.getName());
                             break;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5fa617af3363ec1d71cf8f0a25af43be4b141067
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.4
Gerrit-Owner: Martin Sivák <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to