BGPCEP-742 Fix BGP NPE filter null BGP State
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPStateCollectorImpl.java
index 0937aac4f2e1cb114a4991318e76bdd1cbc0e52f..c865a08eb42cf6cbf7b4ae6b20babcaee17d4552 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.rib.impl.state;
 import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 import javax.annotation.concurrent.GuardedBy;
 import javax.annotation.concurrent.ThreadSafe;
@@ -30,16 +31,22 @@ public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer
     @Override
     public List<BGPRIBState> getRibStats() {
         synchronized (this.bgpRibStates) {
-            return ImmutableList.copyOf(this.bgpRibStates.stream().map(BGPRIBStateConsumer::getRIBState)
-                .collect(Collectors.toList()));
+            return ImmutableList.copyOf(this.bgpRibStates
+                    .stream()
+                    .map(BGPRIBStateConsumer::getRIBState)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList()));
         }
     }
 
     @Override
     public List<BGPPeerState> getPeerStats() {
         synchronized (this.bgpPeerStates) {
-            return ImmutableList.copyOf(this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState)
-                .collect(Collectors.toList()));
+            return ImmutableList.copyOf(this.bgpPeerStates
+                    .stream()
+                    .map(BGPPeerStateConsumer::getPeerState)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList()));
         }
     }