BUG-8929: NPE during singleton startup 70/62870/4
authorYrineu Rodrigues <yrineu.rodrigues@serro.com>
Thu, 7 Sep 2017 21:08:12 +0000 (18:08 -0300)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 5 Oct 2017 06:43:41 +0000 (06:43 +0000)
Avoid NPE when installing features 'odl-bgpcep-bgp-api' and
'odl-bgpcep-bgp-impl' individually

Change-Id: Id651dff7c813544bd07a03b435069de5e723721d
Signed-off-by: Yrineu Rodrigues <yrineu.rodrigues@serro.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java

index df778a927f57bae3a356e3ecbd57d3d7b608b131..247d5e90c405e5c151abb0244ae6aa40304bc39f 100755 (executable)
@@ -49,6 +49,7 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
 import org.opendaylight.protocol.bgp.rib.impl.state.BGPRIBStateImpl;
 import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.BGPRenderStats;
 import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.RIBImplRuntimeMXBeanImpl;
@@ -177,16 +178,21 @@ public final class RIBImpl extends BGPRIBStateImpl implements ClusterSingletonSe
             table.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
         }
 
-        final ChoiceNode routes = this.ribContextRegistry.getRIBSupportContext(key).getRibSupport().emptyRoutes();
-        table.withChild(routes);
-
-        tx.put(LogicalDatastoreType.OPERATIONAL, tableId.build(), table.build());
-        try {
-            tx.submit().checkedGet();
-        } catch (final TransactionCommitFailedException e1) {
-            LOG.error("Failed to initiate LocRIB for key {}", key, e1);
+        final RIBSupportContext supportContext = this.ribContextRegistry.getRIBSupportContext(key);
+        if (supportContext != null) {
+            final ChoiceNode routes = supportContext.getRibSupport().emptyRoutes();
+            table.withChild(routes);
+
+            tx.put(LogicalDatastoreType.OPERATIONAL, tableId.build(), table.build());
+            try {
+                tx.submit().checkedGet();
+            } catch (final TransactionCommitFailedException e1) {
+                LOG.error("Failed to initiate LocRIB for key {}", key, e1);
+            }
+            createLocRibWriter(key);
+        } else {
+            LOG.warn("There's no registered RIB Context for {}", key.getAfi());
         }
-        createLocRibWriter(key);
     }
 
     private synchronized void createLocRibWriter(final TablesKey key) {