ACL: NullPointerException in AclEventListener 79/82979/4
authorShashidhar Raja <shashidharr@altencalsoftlabs.com>
Tue, 9 Jul 2019 13:17:23 +0000 (18:47 +0530)
committerFaseela K <faseela.k@ericsson.com>
Wed, 7 Aug 2019 11:07:58 +0000 (11:07 +0000)
Added validations to check getAccessListEntries() before
using it to access getAce() in AclEventListener

Change-Id: I5d7ddac957111bfcc2b5fee2d91bb8e56f925982
Signed-off-by: Shashidhar Raja <shashidharr@altencalsoftlabs.com>
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclEventListener.java
aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/utils/AclServiceUtils.java

index d939e25275a0bdc2ca636ce11b1e756e5151c34a..5336667a4dc809b8fb4a7af2ad6531a0121cf034 100644 (file)
@@ -100,7 +100,8 @@ public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEv
         if (aclTag != null) {
             this.aclDataUtil.removeAclTag(aclName);
         }
-        updateRemoteAclCache(acl.getAccessListEntries().getAce(), aclName, AclServiceManager.Action.REMOVE);
+
+        updateRemoteAclCache(AclServiceUtils.getAceListFromAcl(acl), aclName, AclServiceManager.Action.REMOVE);
         if (aclClusterUtil.isEntityOwner()) {
             if (aclTag != null) {
                 this.aclServiceUtils.releaseAclTag(aclName);
@@ -164,7 +165,7 @@ public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEv
             this.aclDataUtil.addAclTag(aclName, aclTag);
         }
 
-        updateRemoteAclCache(acl.getAccessListEntries().getAce(), aclName, AclServiceManager.Action.ADD);
+        updateRemoteAclCache(AclServiceUtils.getAceListFromAcl(acl), aclName, AclServiceManager.Action.ADD);
     }
 
     /**
@@ -175,9 +176,6 @@ public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEv
      * @param action the action
      */
     private void updateRemoteAclCache(@Nullable List<Ace> aceList, String aclName, AclServiceManager.Action action) {
-        if (null == aceList) {
-            return;
-        }
         for (Ace ace : aceList) {
             SecurityRuleAttr aceAttributes = ace.augmentation(SecurityRuleAttr.class);
             if (AclServiceUtils.doesAceHaveRemoteGroupId(aceAttributes)) {
index 9620850f0403d2dc746947b91acb0a80a411210d..78ad64fdc6d9ba523f1ee41022736efd5668ec8b 100644 (file)
@@ -952,6 +952,17 @@ public final class AclServiceUtils {
         return flowMatches;
     }
 
+    public static List<Ace> getAceListFromAcl(Acl acl) {
+        if (acl.getAccessListEntries() != null) {
+            List<Ace> aceList = acl.getAccessListEntries().getAce();
+            if (aceList != null && !aceList.isEmpty()
+                    && aceList.get(0).augmentation(SecurityRuleAttr.class) != null) {
+                return aceList;
+            }
+        }
+        return Collections.emptyList();
+    }
+
     /**
      * Builds the ip protocol matches.
      *