Elan interface add throwing NPE 99/83499/3
authorzhangninglc <zhangninglc@inspur.com>
Wed, 7 Aug 2019 08:28:04 +0000 (16:28 +0800)
committerStephen Kitt <skitt@redhat.com>
Thu, 8 Aug 2019 07:28:42 +0000 (07:28 +0000)
Issue Description:
=================
Elan instance name may be null, add to ConcurrentHashMap must throw NPE

ERROR | opendaylight-cluster-data-notification-dispatcher-40 |
DataTreeChangeListenerActor      | 235 -
org.opendaylight.controller.sal-clustering-commons - 1.9.1 |
member-2-shard-default-config: Error notifying listener
org.opendaylight.genius.mdsalutil.cache.DataObjectCache$$Lambda$1291/872119028@32410eae
java.lang.NullPointerException: null
    at org.opendaylight.netvirt.elan.cache.ElanInterfaceCache.added(ElanInterfaceCache.java:75)
    at org.opendaylight.netvirt.elan.cache.ElanInterfaceCache.added(ElanInterfaceCache.java:37)

Solution:
=========
Determine that the Elan instance name cannot be null before adding

Change-Id: I21f2f93427aec92b708725dd41aa37cd37e7dcac
Signed-off-by: zhangninglc <zhangninglc@inspur.com>
elanmanager/impl/src/main/java/org/opendaylight/netvirt/elan/cache/ElanInterfaceCache.java

index 20dc778c4094d4c42c7b455fb7d8f2aa8800042f..975885b043a4e52d3bf6ceae700e59afef5c05df 100644 (file)
@@ -72,8 +72,10 @@ public class ElanInterfaceCache extends InstanceIdDataObjectCache<ElanInterface>
 
     @Override
     protected void added(InstanceIdentifier<ElanInterface> path, ElanInterface elanInterface) {
-        elanInstanceToInterfacesCache.computeIfAbsent(elanInterface.getElanInstanceName(),
-            key -> ConcurrentHashMap.newKeySet()).add(elanInterface.getName());
+        if (null != elanInterface.getElanInstanceName() && null != elanInterface.getName()) {
+            elanInstanceToInterfacesCache.computeIfAbsent(elanInterface.getElanInstanceName(),
+                key -> ConcurrentHashMap.newKeySet()).add(elanInterface.getName());
+        }
     }
 
     @Override