{"record":{"id":"f51e660e98c8ef0a","repo":"json-path/JsonPath","slug":"the-path-is-null","errorCode":null,"errorMessage":"The path  is null","messagePattern":"The path  is null","errorType":"exception","errorClass":"PathNotFoundException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayPathToken.java","lineNumber":40,"sourceCode":"\npublic abstract class ArrayPathToken extends PathToken {\n\n    /**\n     * Check if model is non-null and array.\n     * @param currentPath\n     * @param model\n     * @param ctx\n     * @return false if current evaluation call must be skipped, true otherwise\n     * @throws PathNotFoundException if model is null and evaluation must be interrupted\n     * @throws InvalidPathException if model is not an array and evaluation must be interrupted\n     */\n    protected boolean checkArrayModel(String currentPath, Object model, EvaluationContextImpl ctx) {\n        if (model == null){\n            if (!isUpstreamDefinite()\n                    || ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)) {\n                return false;\n            } else {\n                throw new PathNotFoundException(\"The path \" + currentPath + \" is null\");\n            }\n        }\n        if (!ctx.jsonProvider().isArray(model)) {\n            if (!isUpstreamDefinite()\n                    || ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)) {\n                return false;\n            } else {\n                throw new PathNotFoundException(format(\"Filter: %s can only be applied to arrays. Current context is: %s\", toString(), model));\n            }\n        }\n        return true;\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":54,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayPathToken.java#L22-L54","documentation":"checkArrayModel() on ArrayPathToken is called when evaluating array index/slice tokens. If the model at currentPath is null (the parent path did not resolve), the token throws PathNotFoundException('The path <currentPath> is null') — unless upstream is indefinite (wildcards/filters, where missing branches are tolerated) or Option.SUPPRESS_EXCEPTIONS is set.","triggerScenarios":"Reading a path like $.a.b[0] where $.a.b does not exist in the document, via JsonPath.read() without SUPPRESS_EXCEPTIONS and with a definite (non-wildcard) upstream path.","commonSituations":"Assuming optional JSON fields exist (documents from different API versions), reading indexes into arrays behind missing parents, deserialized/partial documents, or tests using minimal fixtures.","solutions":["Add Option.SUPPRESS_EXCEPTIONS to the Configuration and handle the returned null/absent value.","Validate the document shape (e.g. a null check on the parent) before running the indexed path.","Use JsonPath.read(path, returnType, new Configuration.Defaults...) with a default or catch PathNotFoundException.","Fix the path or the fixture so the intermediate path exists."],"exampleFix":"// before\nList<Object> first = JsonPath.read(json, \"$.orders.items[0]\"); // orders missing -> PathNotFoundException\n// after\nConfiguration cfg = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();\nList<Object> first = JsonPath.using(cfg).read(json, \"$.orders.items[0]\");","handlingStrategy":"try-catch","validationCode":"Object parent = JsonPath.read(json, \"$.orders\");\nif (parent == null) return Collections.emptyList(); // skip indexed read","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.read(json, \"$.orders.items[0]\");\n} catch (PathNotFoundException e) {\n    if (e.getMessage().contains(\"is null\")) return Collections.emptyList(); // parent missing\n    throw e;\n}","preventionTips":["Enable Option.SUPPRESS_EXCEPTIONS for optional fields","Null-check intermediate paths before indexed access","Model optional JSON fields explicitly in fixtures and API contracts"],"tags":["json-path","path-not-found","missing-field"],"backgroundTag":"file-not-found","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}