spark85 / json-path

Automatically exported from code.google.com/p/json-path
0 stars 0 forks source link

Non-array syntax for array blocks throws NPE #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Json blocks which are arrays must have array syntax first. If not, 
ArrayIndexFilter throws NPE.

What steps will reproduce the problem?
1. Json like: [{\"a\":[{\"b\":1,\"c\":2}]}]
2. jsonpath like: $.a.b
3. calling JsonPath.read("[{\"a\":[{\"b\":1,\"c\":2}]}]", "$.a");  

What is the expected output? What do you see instead?
Expected output is null because the json is an array and needs a [X] to address 
an element.

Actual output:
java.lang.NullPointerException
        at com.jayway.jsonpath.internal.filter.ArrayIndexFilter.filter(ArrayIndexFilter.java:66)
        at com.jayway.jsonpath.internal.filter.PathTokenFilter.filter(PathTokenFilter.java:50)
        at com.jayway.jsonpath.JsonPath.read(JsonPath.java:182)
        at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
        at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
        at me.(JUnitTestClass.java:52)

What version of the product are you using? On what operating system?
Happens in 0.8.0, also 0.8.2

Please provide any additional information below.

Original issue reported on code.google.com by norskh...@gmail.com on 6 Feb 2013 at 8:07

GoogleCodeExporter commented 9 years ago
I'm not sure that null is the correct result here. I've improved the Exception 
and stack trace.

com.jayway.jsonpath.InvalidPathException: Trying to access the field 'a' in an 
array context.
    at com.jayway.jsonpath.internal.filter.FieldFilter.filter(FieldFilter.java:41)
    at com.jayway.jsonpath.JsonPath.read(JsonPath.java:220)

Original comment by kalle.st...@gmail.com on 20 Aug 2013 at 12:08