Fix NPE when there's no secondary path.
Change-Id: I3bb8eeb2abf140d44cf4dc7186cf1bf316c23f70
diff --git a/core/api/src/main/java/org/onosproject/net/DisjointPath.java b/core/api/src/main/java/org/onosproject/net/DisjointPath.java
index 39059f4..39237ea 100644
--- a/core/api/src/main/java/org/onosproject/net/DisjointPath.java
+++ b/core/api/src/main/java/org/onosproject/net/DisjointPath.java
@@ -43,7 +43,7 @@
/**
* Gets secondary path.
*
- * @return secondary path
+ * @return secondary path, or null if there is no secondary path available.
*/
Path backup();
}
diff --git a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
index 8c4fbc8..72780d3 100644
--- a/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
+++ b/core/common/src/main/java/org/onosproject/common/DefaultTopology.java
@@ -482,6 +482,12 @@
}
private DisjointPath networkDisjointPath(DisjointPathPair<TopologyVertex, TopologyEdge> path) {
+ if (!path.hasBackup()) {
+ // There was no secondary path available.
+ return new DefaultDisjointPath(CORE_PROVIDER_ID,
+ (DefaultPath) networkPath(path.primary()),
+ null);
+ }
return new DefaultDisjointPath(CORE_PROVIDER_ID,
(DefaultPath) networkPath(path.primary()),
(DefaultPath) networkPath(path.secondary()));
diff --git a/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java b/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java
index 0e25116..1e8d3d6 100644
--- a/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java
+++ b/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java
@@ -66,7 +66,7 @@
/**
* Returns the secondary path.
*
- * @return primary path
+ * @return secondary path, or null if there is no secondary path available.
*/
public Path<V, E> secondary() {
return secondary;