BUG-8929: NPE during singleton startup 01/64101/1
authorYrineu Rodrigues <yrineu.rodrigues@serro.com>
Thu, 7 Sep 2017 21:08:12 +0000 (18:08 -0300)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Tue, 10 Oct 2017 06:53:05 +0000 (06:53 +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>
(cherry picked from commit ab128ea6a1ee1fd19578326049bbfd8084a250c4)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java

index b88291bf01855ee8edd53fc69cf008b4d449d0b5..ee981d8044bb2406e65be1d9028a276a3183b029 100755 (executable)
@@ -48,6 +48,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;
@@ -176,16 +177,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) {