[ONOS-7372] GossipDeviceStore cannot do 'mark off line' for a removed device in a controller recovered from  failure

Change-Id: If566cfa6af376b2792cd8b978189a885e28ec89c
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
index 67066fd..90e115a 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
@@ -486,17 +486,15 @@
             // accept off-line if given timestamp is newer than
             // the latest Timestamp from Primary provider
             DeviceDescriptions primDescs = getPrimaryDescriptions(providerDescs);
-            if (primDescs == null) {
-                return null;
-            }
-
-            Timestamp lastTimestamp = primDescs.getLatestTimestamp();
-            if (lastTimestamp == null) {
-                lastTimestamp = deviceClockService.getTimestamp(deviceId);
-            }
-            if (timestamp.compareTo(lastTimestamp) <= 0) {
-                // outdated event ignore
-                return null;
+            if (primDescs != null) {
+                Timestamp lastTimestamp = primDescs.getLatestTimestamp();
+                if (lastTimestamp == null) {
+                    lastTimestamp = deviceClockService.getTimestamp(deviceId);
+                }
+                if (timestamp.compareTo(lastTimestamp) <= 0) {
+                    // outdated event ignore
+                    return null;
+                }
             }
 
             offline.put(deviceId, timestamp);
@@ -1456,8 +1454,7 @@
 
                 // checking if remote timestamp is more recent.
                 Timestamp rOffline = offlineAds.get(deviceId);
-                if (rOffline != null &&
-                        rOffline.compareTo(localLatest) > 0) {
+                if (localLatest == null || (rOffline != null && rOffline.compareTo(localLatest) > 0)) {
                     // remote offline timestamp suggests that the
                     // device is off-line
                     markOfflineInternal(deviceId, rOffline);