Fix NPE in DistributedFlowStatisticStore

Change-Id: If2cbae329000d1cc5ef5b1ca32980e460be2b263
diff --git a/core/store/dist/src/main/java/org/onosproject/store/statistic/impl/DistributedFlowStatisticStore.java b/core/store/dist/src/main/java/org/onosproject/store/statistic/impl/DistributedFlowStatisticStore.java
index 40c3e2d..0cd4a83 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/statistic/impl/DistributedFlowStatisticStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/statistic/impl/DistributedFlowStatisticStore.java
@@ -44,6 +44,7 @@
 import java.util.Collections;

 import java.util.HashSet;

 import java.util.Map;

+import java.util.Optional;

 import java.util.Set;

 import java.util.concurrent.ConcurrentHashMap;

 import java.util.concurrent.ExecutorService;

@@ -164,16 +165,16 @@
         if (curr == null) {

             addFlowStatistic(rule);

         } else {

-            FlowEntry f = curr.stream().filter(c -> rule.equals(c)).

-                    findAny().orElse(null);

-            if (rule.bytes() < f.bytes()) {

+            Optional<FlowEntry> f = curr.stream().filter(c -> rule.equals(c)).

+                    findAny();

+            if (f.isPresent() && rule.bytes() < f.get().bytes()) {

                 log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" +

                         " Invalid Flow Update! Will be removed!!" +

                         " curr flowId=" + Long.toHexString(rule.id().value()) +

-                        ", prev flowId=" + Long.toHexString(f.id().value()) +

-                        ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.bytes() +

-                        ", curr life=" + rule.life() + ", prev life=" + f.life() +

-                        ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.lastSeen());

+                        ", prev flowId=" + Long.toHexString(f.get().id().value()) +

+                        ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.get().bytes() +

+                        ", curr life=" + rule.life() + ", prev life=" + f.get().life() +

+                        ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.get().lastSeen());

                 // something is wrong! invalid flow entry, so delete it

                 removeFlowStatistic(rule);

                 return;

@@ -185,10 +186,10 @@
             }

 

             // previous one is exist

-            if (f != null) {

+            if (f.isPresent()) {

                 // remove old one and add new one

                 prev.remove(rule);

-                if (!prev.add(f)) {

+                if (!prev.add(f.get())) {

                     log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" +

                                     " flowId={}, add failed into previous.",

                             Long.toHexString(rule.id().value()));