Avoid NPE when PCC node was cleaned up from the topology. 18/14018/1
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 9 Jan 2015 14:51:55 +0000 (15:51 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 9 Jan 2015 14:51:55 +0000 (15:51 +0100)
Change-Id: I9a232dba0726517f09f2ae0945910e989e8ecaab
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListener.java

index 301561c0743a5dc34f5f2339a1db9262279fda09..6d8874174357858c070931632fa3201f6de5918b 100644 (file)
@@ -443,7 +443,17 @@ public abstract class AbstractTopologySessionListener<S, L> implements PCEPSessi
         return this.lsps.get(id);
     }
 
+    /**
+     * Reads operational data on this node. Doesn't attempt to read the data,
+     * if the node does not exist. In this case returns null.
+     *
+     * @param id InstanceIdentifier of the node
+     * @return null if the node does not exists, or operational data
+     */
     protected final synchronized <T extends DataObject> ListenableFuture<Optional<T>> readOperationalData(final InstanceIdentifier<T> id) {
+        if (this.nodeState == null) {
+            return null;
+        }
         return this.nodeState.readOperationalData(id);
     }
 
index 572da1b77e86d59446e7d9eeb0ecb20f413d588c..5bbb52d76ec1bf45c062226cecb8ff497301cb43 100644 (file)
@@ -221,6 +221,9 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         // Make sure there is no such LSP
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
+        if (f == null) {
+            return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
+        }
 
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
@@ -270,6 +273,9 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         // Make sure the LSP exists, we need it for PLSP-ID
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
+        if (f == null) {
+            return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
+        }
 
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
@@ -297,6 +303,9 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         // Make sure the LSP exists
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
+        if (f == null) {
+            return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
+        }
 
         return Futures.transform(f, new AsyncFunction<Optional<ReportedLsp>, OperationResult>() {
             @Override
@@ -357,6 +366,9 @@ final class Stateful07TopologySessionListener extends AbstractTopologySessionLis
         final InstanceIdentifier<ReportedLsp> lsp = lspIdentifier(input.getName());
         LOG.debug("Checking if LSP {} has operational state {}", lsp, op);
         final ListenableFuture<Optional<ReportedLsp>> f = readOperationalData(lsp);
+        if (f == null) {
+            return OperationResults.createUnsent(PCEPErrors.LSP_INTERNAL_ERROR).future();
+        }
 
         return Futures.transform(f, new Function<Optional<ReportedLsp>, OperationResult>() {
             @Override