Bug 6604 - Fix NPE in AbstractBgpTopologyProvider#topologyTypeFilter 61/45061/2
authorMilos Fabian <milfabia@cisco.com>
Thu, 1 Sep 2016 08:39:52 +0000 (10:39 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 2 Sep 2016 12:08:52 +0000 (12:08 +0000)
The BGP topology provider is not the only ODL component which is writing to
config DS network-topology node (i.e. netconf-topology).

Make the code more defensive to avoid NPE when filtering topologies' configuration
without topology-type container.

Change-Id: I493759ce23277ac6b4c5f15653708c853426e56b
Signed-off-by: Milos Fabian <milfabia@cisco.com>
(cherry picked from commit 9cfa9f12dbc439cc8fde08794db823de534d5366)

bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/config/AbstractBgpTopologyProvider.java

index 5728a0804253a1e41c68ef65d15197674de8a8fc..370b76f5eb8f6771e9b9c61c804227dba013cd79 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
 import org.opendaylight.yangtools.concepts.AbstractRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -73,11 +74,13 @@ abstract class AbstractBgpTopologyProvider implements BgpTopologyProvider, AutoC
 
     @Override
     public final boolean topologyTypeFilter(final Topology topology) {
-        final TopologyTypes1 topologyTypes = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+        final TopologyTypes topologyTypes = topology.getTopologyTypes();
         if (topologyTypes == null) {
             return false;
         }
-        return topologyTypeFilter(topologyTypes);
+
+        final TopologyTypes1 aug = topologyTypes.getAugmentation(TopologyTypes1.class);
+        return aug != null && topologyTypeFilter(aug);
     }
 
     private TopologyReferenceSingletonService createInstance(final Topology topology, final Function<Topology, Void> writeFunction) {