Bug 3798: Fix NPE when restoring dao from an empty mdsal datastore 65/22865/1
authorFlorin Coras <fcoras@cisco.com>
Thu, 18 Jun 2015 08:55:49 +0000 (01:55 -0700)
committerLori Jakab <lorand.jakab@gmail.com>
Thu, 18 Jun 2015 09:27:39 +0000 (09:27 +0000)
Change-Id: I14b53e1455fc653ced92906247f2d84232148135
Signed-off-by: Florin Coras <fcoras@cisco.com>
(cherry picked from commit 0456793ff120dc7a643053efbf83dad240493697)

mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/mdsal/DataStoreBackEnd.java

index ce36c5ddb2cdf65b6f67243cfc97607ffff4c42f..ef05bf01ff716e9547db0b535ae6db07bf99e998 100644 (file)
@@ -117,7 +117,10 @@ public class DataStoreBackEnd {
 
         if (mdb != null) {
             for (InstanceId id : mdb.getInstanceId()) {
-                mappings.addAll(id.getMapping());
+                List<Mapping> ms = id.getMapping();
+                if (ms != null) {
+                    mappings.addAll(ms);
+                }
             }
         }
 
@@ -126,17 +129,20 @@ public class DataStoreBackEnd {
 
     public List<AuthenticationKey> getAllAuthenticationKeys() {
         LOG.debug("MD-SAL: Get all authentication keys from datastore");
-        List<AuthenticationKey> keys = new ArrayList<AuthenticationKey>();
+        List<AuthenticationKey> authKeys = new ArrayList<AuthenticationKey>();
         InstanceIdentifier<MappingDatabase> path = InstanceIdentifier.create(MappingDatabase.class);
         MappingDatabase mdb = readTransaction(path, LogicalDatastoreType.CONFIGURATION);
 
         if (mdb != null) {
             for (InstanceId id : mdb.getInstanceId()) {
-                keys.addAll(id.getAuthenticationKey());
+                List<AuthenticationKey> keys = id.getAuthenticationKey();
+                if (keys != null) {
+                    authKeys.addAll(keys);
+                }
             }
         }
 
-        return keys;
+        return authKeys;
     }
 
     private <U extends org.opendaylight.yangtools.yang.binding.DataObject> boolean writePutTransaction(