Skip to content

Commit 2c5e2cc

Browse files
committed
issue #345 better error for path segment missing in JSONPointer
1 parent e58e132 commit 2c5e2cc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Diff for: unirest/src/main/java/kong/unirest/json/JSONPointer.java

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ public Object queryFrom(Object object) throws JSONPointerException {
178178
Queryable e = verify(object);
179179
Object o = e.querySection(section);
180180
if (next != null) {
181+
if(o == null){
182+
throw new JSONPointerException("Path Segment Missing: " + section);
183+
}
181184
return next.queryFrom(o);
182185
}
183186
return o;

Diff for: unirest/src/test/java/kong/unirest/json/JSONPointerTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public void invalidPathQuery() {
5151
"a JSON pointer should start with '/' or '#/'");
5252
}
5353

54+
@Test
55+
public void invalidPathQuery_downpath() {
56+
TestUtil.assertException(() -> obj.query("/shwoop/dedoop"),
57+
JSONPointerException.class,
58+
"Path Segment Missing: shwoop");
59+
}
60+
5461
@Test
5562
public void arrayPartThatDoesNotExist() {
5663
TestUtil.assertException(() -> obj.query("/foo/5"),

0 commit comments

Comments
 (0)