Fix Graph deletion which cause NPE 71/98371/1
authorOlivier Dugeon <olivier.dugeon@orange.com>
Tue, 9 Nov 2021 10:12:16 +0000 (11:12 +0100)
committerOlivier Dugeon <olivier.dugeon@orange.com>
Tue, 9 Nov 2021 10:12:16 +0000 (11:12 +0100)
Graph is deleted twice when stopping ODL which cause a NPE.

When ODL stops, AbstractTopologyBuilder() calls
LinkStateGraphBuilder.clearTopology() which call
ConnectedGraphImpl.clear(). Then ConnectedGraphServer() stops by
calling destroyOperationalGraphModel() which browse all stored graphs
and call again ConnectedGraphImpl.clear() which cause the NPE.

Fix removes graph from ConnectedGraphServer graphs Map in
clearGraph() method instead of deleteGraph() method.

JIRA: BGPCEP-977

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Change-Id: I55209e77ffa2c317ea85ca29cc794016f338c488

graph/graph-impl/src/main/java/org/opendaylight/graph/impl/ConnectedGraphServer.java

index 9626ac7ee4988fc8bc42da3965ca79c5c710397a..2be0d247a8dc777fa4122396edf09940188d87c9 100644 (file)
@@ -278,6 +278,7 @@ public final class ConnectedGraphServer implements ConnectedGraphProvider, Trans
     public void clearGraph(final Graph graph) {
         Preconditions.checkArgument(graph != null, "Provided Graph is a null object");
         removeFromDataStore(getGraphInstanceIdentifier(graph.getName()), "Graph(" + graph.getName() + ")");
+        graphs.remove(graph.key());
     }
 
     /**
@@ -436,7 +437,7 @@ public final class ConnectedGraphServer implements ConnectedGraphProvider, Trans
     @Override
     public void deleteGraph(final GraphKey key) {
         Preconditions.checkArgument(key != null, "Provided Graph Key is a null object");
-        ConnectedGraphImpl cgraph = graphs.remove(key);
+        ConnectedGraphImpl cgraph = graphs.get(key);
         /*
          * Remove the corresponding Connected Graph which will delete the graph
          * by calling clearGraph() method (see above)