Committed by
Gerrit Code Review
Fix NPE in DistributedFlowStatisticStore
Change-Id: If2cbae329000d1cc5ef5b1ca32980e460be2b263
Showing
1 changed file
with
10 additions
and
9 deletions
... | @@ -44,6 +44,7 @@ import org.slf4j.Logger; | ... | @@ -44,6 +44,7 @@ import org.slf4j.Logger; |
44 | import java.util.Collections; | 44 | import java.util.Collections; |
45 | import java.util.HashSet; | 45 | import java.util.HashSet; |
46 | import java.util.Map; | 46 | import java.util.Map; |
47 | +import java.util.Optional; | ||
47 | import java.util.Set; | 48 | import java.util.Set; |
48 | import java.util.concurrent.ConcurrentHashMap; | 49 | import java.util.concurrent.ConcurrentHashMap; |
49 | import java.util.concurrent.ExecutorService; | 50 | import java.util.concurrent.ExecutorService; |
... | @@ -164,16 +165,16 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { | ... | @@ -164,16 +165,16 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { |
164 | if (curr == null) { | 165 | if (curr == null) { |
165 | addFlowStatistic(rule); | 166 | addFlowStatistic(rule); |
166 | } else { | 167 | } else { |
167 | - FlowEntry f = curr.stream().filter(c -> rule.equals(c)). | 168 | + Optional<FlowEntry> f = curr.stream().filter(c -> rule.equals(c)). |
168 | - findAny().orElse(null); | 169 | + findAny(); |
169 | - if (rule.bytes() < f.bytes()) { | 170 | + if (f.isPresent() && rule.bytes() < f.get().bytes()) { |
170 | log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + | 171 | log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + |
171 | " Invalid Flow Update! Will be removed!!" + | 172 | " Invalid Flow Update! Will be removed!!" + |
172 | " curr flowId=" + Long.toHexString(rule.id().value()) + | 173 | " curr flowId=" + Long.toHexString(rule.id().value()) + |
173 | - ", prev flowId=" + Long.toHexString(f.id().value()) + | 174 | + ", prev flowId=" + Long.toHexString(f.get().id().value()) + |
174 | - ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.bytes() + | 175 | + ", curr bytes=" + rule.bytes() + ", prev bytes=" + f.get().bytes() + |
175 | - ", curr life=" + rule.life() + ", prev life=" + f.life() + | 176 | + ", curr life=" + rule.life() + ", prev life=" + f.get().life() + |
176 | - ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.lastSeen()); | 177 | + ", curr lastSeen=" + rule.lastSeen() + ", prev lastSeen=" + f.get().lastSeen()); |
177 | // something is wrong! invalid flow entry, so delete it | 178 | // something is wrong! invalid flow entry, so delete it |
178 | removeFlowStatistic(rule); | 179 | removeFlowStatistic(rule); |
179 | return; | 180 | return; |
... | @@ -185,10 +186,10 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { | ... | @@ -185,10 +186,10 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { |
185 | } | 186 | } |
186 | 187 | ||
187 | // previous one is exist | 188 | // previous one is exist |
188 | - if (f != null) { | 189 | + if (f.isPresent()) { |
189 | // remove old one and add new one | 190 | // remove old one and add new one |
190 | prev.remove(rule); | 191 | prev.remove(rule); |
191 | - if (!prev.add(f)) { | 192 | + if (!prev.add(f.get())) { |
192 | log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + | 193 | log.debug("DistributedFlowStatisticStore:updateFlowStatistic():" + |
193 | " flowId={}, add failed into previous.", | 194 | " flowId={}, add failed into previous.", |
194 | Long.toHexString(rule.id().value())); | 195 | Long.toHexString(rule.id().value())); | ... | ... |
-
Please register or login to post a comment