commit | b2a20d1138053e4dcc1ede8383509a859984520e | [log] [tgz] |
---|---|---|
author | Yuta HIGUCHI <y-higuchi@ak.jp.nec.com> | Wed Feb 14 10:25:55 2018 -0800 |
committer | Thomas Vachuska <tom@opennetworking.org> | Thu Feb 15 19:29:42 2018 +0000 |
tree | 0a6563291f825358b45daa984c954b18133f75c5 | |
parent | 0e84f44bfc8c063e9a4ca3fa9f4d3eae66e48416 [diff] |
null-safe DocPath ancentry tests Change-Id: I36709bee94b10e516427adb892d1caeabea1b9aa
diff --git a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java index ed5de9f..8c969aa 100644 --- a/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java +++ b/core/api/src/main/java/org/onosproject/store/service/DocumentPath.java
@@ -172,7 +172,8 @@ * @return {@code true} is yes; {@code false} otherwise. */ public boolean isAncestorOf(DocumentPath other) { - return this.pathElements.size() < other.pathElements.size() && + return other != null && + this.pathElements.size() < other.pathElements.size() && this.pathElements.equals(other.pathElements.subList(0, this.pathElements.size())); } @@ -186,7 +187,8 @@ * @return {@code true} is yes; {@code false} otherwise. */ public boolean isDescendentOf(DocumentPath other) { - return other.equals(this) || other.isAncestorOf(this); + return other != null && + (other.equals(this) || other.isAncestorOf(this)); } /**
diff --git a/core/api/src/test/java/org/onosproject/store/service/DocumentPathTest.java b/core/api/src/test/java/org/onosproject/store/service/DocumentPathTest.java index 19c34bd..431f58f 100644 --- a/core/api/src/test/java/org/onosproject/store/service/DocumentPathTest.java +++ b/core/api/src/test/java/org/onosproject/store/service/DocumentPathTest.java
@@ -60,6 +60,9 @@ assertTrue(path3.isDescendentOf(path3)); assertTrue(path3.isDescendentOf(path1)); assertFalse(path3.isDescendentOf(path2)); + + assertFalse(path.isDescendentOf(null)); + assertFalse(path.isAncestorOf(null)); } @Rule