Bug 4976: Fix NPE in SimpleMapCache 20/32820/2
authorLorand Jakab <lojakab@cisco.com>
Sun, 17 Jan 2016 20:35:33 +0000 (22:35 +0200)
committerLorand Jakab <lojakab@cisco.com>
Sun, 17 Jan 2016 20:35:33 +0000 (22:35 +0200)
Change-Id: I0647c2b539876f319d71bb2186eee5a07ee3f300
Signed-off-by: Lorand Jakab <lojakab@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/mapcache/SimpleMapCache.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/MappingMergeUtil.java

index b8590b6cee9798fdd955beea5d9158391d5ef8b4..b33bf33390ac25500d0f4280aff11ac1113ee0ba 100644 (file)
@@ -233,7 +233,8 @@ public class SimpleMapCache implements IMapCache {
                 ILispDAO xtrIdTable = getXtrIdTable(eid, (ILispDAO) daoEntry.getValue().get(SubKeys.XTRID_RECORDS));
                 if (xtrIdTable != null) {
                     MappingRecord xtrIdRecord = (MappingRecord) xtrIdTable.getSpecific(xtrId, SubKeys.RECORD);
-                    if (MappingMergeUtil.timestampIsExpired(xtrIdRecord.getTimestamp())) {
+                    if (xtrIdRecord.getTimestamp() != null &&
+                            MappingMergeUtil.timestampIsExpired(xtrIdRecord.getTimestamp())) {
                         xtrIdTable.removeSpecific(xtrId, SubKeys.RECORD);
                         return null;
                     } else {
@@ -244,7 +245,7 @@ public class SimpleMapCache implements IMapCache {
                 }
             } else {
                 Date timestamp = (Date) daoEntry.getValue().get(SubKeys.REGDATE);
-                if (MappingMergeUtil.timestampIsExpired(timestamp)) {
+                if (timestamp != null && MappingMergeUtil.timestampIsExpired(timestamp)) {
                     dao.removeSpecific(daoEntry.getKey(), SubKeys.REGDATE);
                     dao.removeSpecific(daoEntry.getKey(), SubKeys.RECORD);
                     return null;
index 104c89505e50bcf26260ff121cb366f794f49d57..0423b5c9bcc49388a32abea2bbe8d2e37e986623 100644 (file)
@@ -21,6 +21,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rl
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Utility class to implement merging of locator sets
  *
@@ -157,10 +159,12 @@ public final class MappingMergeUtil {
     }
 
     public static boolean timestampIsExpired(Date timestamp) {
+        Preconditions.checkNotNull(timestamp, "timestamp should not be null!");
         return timestampIsExpired(timestamp.getTime());
     }
 
-    public static boolean timestampIsExpired(long timestamp) {
+    public static boolean timestampIsExpired(Long timestamp) {
+        Preconditions.checkNotNull(timestamp, "timestamp should not be null!");
         if ((System.currentTimeMillis() - timestamp) > REGISTRATION_VALIDITY) {
             return true;
         }