ofri masad has uploaded a new change for review.

Change subject: core: Fix NPE in QuotaManager (#854895)
......................................................................

core: Fix NPE in QuotaManager (#854895)

https://bugzilla.redhat.com/854895

This patch adds handling null storage pool passed to QuotaManager
methods. In case of null storage pool, the storage pool will be
extracted from the quota (passed to the method).

Change-Id: I640f936fccf7973f80cabb61d41733e8b63fc699
Signed-off-by: Ofri Masad <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
1 file changed, 30 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/7906/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
index c17f4b1..535b174 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
@@ -100,6 +100,12 @@
     }
 
     public void rollbackQuota(storage_pool storagePool, List<Guid> quotaList) {
+        if (storagePool == null){
+            if (quotaList == null || quotaList.isEmpty()) {
+                return;
+            }
+            storagePool = extractStoragePoolFromQuota(quotaList.get(0));
+        }
         rollbackQuota(storagePool.getId(), quotaList);
     }
 
@@ -147,6 +153,14 @@
         Pair<AuditLogType, AuditLogableBase> logPair = new Pair<AuditLogType, 
AuditLogableBase>();
         lock.readLock().lock();
         try {
+            if (storagePool == null){
+                log.debug("Null storage pool was passed to 
'QuotaManager.validateAndSetStorageQuota()'");
+                if (parameters.isEmpty() || parameters.get(0).getQuotaId() == 
null) {
+                    
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
+                    return false;
+                }
+                storagePool = 
extractStoragePoolFromQuota(parameters.get(0).getQuotaId());
+            }
             if 
(QuotaEnforcementTypeEnum.DISABLED.equals(storagePool.getQuotaEnforcementType()))
 {
                 return true;
             }
@@ -476,6 +490,14 @@
             ArrayList<String> canDoActionMessages) {
         Pair<AuditLogType, AuditLogableBase> logPair = new Pair<AuditLogType, 
AuditLogableBase>();
         try {
+            if (storagePool == null){
+                log.debug("Null storage pool was passed to 
'QuotaManager.validateAndSetStorageQuota()'");
+                if (quotaId == null) {
+                    
canDoActionMessages.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
+                    return false;
+                }
+                storagePool = extractStoragePoolFromQuota(quotaId);
+            }
             if 
(QuotaEnforcementTypeEnum.DISABLED.equals(storagePool.getQuotaEnforcementType()))
 {
                 return true;
             }
@@ -601,4 +623,12 @@
         }
         return false;
     }
+
+    private storage_pool extractStoragePoolFromQuota(Guid quotaId) {
+        storage_pool storagePool;Quota quota = getQuotaDAO().getById(quotaId);
+        storagePool = new storage_pool();
+        storagePool.setId(quota.getStoragePoolId());
+        storagePool.setQuotaEnforcementType(quota.getQuotaEnforcementType());
+        return storagePool;
+    }
 }


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

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

Reply via email to