{"record":{"id":"5cf86ac8f1d24cbb","repo":"json-path/JsonPath","slug":"expected-undefined-node","errorCode":null,"errorMessage":"Expected undefined node","messagePattern":"Expected undefined node","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java","lineNumber":92,"sourceCode":"\n    public boolean isValueListNode() {\n        return false;\n    }\n\n    public ValueListNode asValueListNode() {\n        throw new InvalidPathException(\"Expected value list node\");\n    }\n\n    public boolean isNullNode() {\n        return false;\n    }\n\n    public NullNode asNullNode() {\n        throw new InvalidPathException(\"Expected null node\");\n    }\n\n    public UndefinedNode asUndefinedNode() {\n        throw new InvalidPathException(\"Expected undefined node\");\n    }\n\n    public boolean isUndefinedNode() {\n        return false;\n    }\n\n    public boolean isClassNode() {\n        return false;\n    }\n\n    public ClassNode asClassNode() {\n        throw new InvalidPathException(\"Expected class node\");\n    }\n\n    //workaround for issue: https://github.com/json-path/JsonPath/issues/613\n    public boolean isOffsetDateTimeNode(){\n        return false;\n    }","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java#L74-L110","documentation":"ValueNode's base asUndefinedNode() throws InvalidPathException(\"Expected undefined node\") when called on a node that is not an UndefinedNode. UndefinedNode represents a missing/absent value during filter evaluation; the base class throws by default since only UndefinedNode supports this downcast. It fires when evaluation logic requires an 'undefined' operand but receives a concrete value node.","triggerScenarios":"Filter logic distinguishing missing fields from null where the operand is a concrete value — e.g. an operator or code path calling asUndefinedNode() on a StringNode/NumberNode; expressions whose semantics assume the field is absent but the field actually exists in the document.","commonSituations":"Schema drift where a previously missing (undefined) field is now present with an empty value, so code that assumed UndefinedNode breaks; custom operators on the internal ValueNode API.","solutions":["Adjust the filter to check for the concrete value present instead of expecting absence, e.g. @.field == '' for empty strings","Ensure optional fields are actually omitted (not set to placeholders) if logic relies on undefined semantics","Handle both undefined and default-value cases in the predicate, e.g. @.field == null || @.field == ''","Catch InvalidPathException around evaluation when distinguishing missing vs present values"],"exampleFix":"// before\n$.items[?(@.nickname == null)] // nickname exists as empty string; not undefined/null\n// after\n$.items[?(@.nickname == null || @.nickname == '')]","handlingStrategy":"type-guard","validationCode":"Map<String,Object> item = JsonPath.parse(json).read(\"$.item\");\nboolean undefined = !item.containsKey(\"nickname\"); // distinguish absent vs present-with-default","typeGuard":"static boolean isUndefined(DocumentContext ctx, String path) { try { return ctx.read(path) == null && !((Map)ctx.json()).containsKey(lastKey(path)); } catch (PathNotFoundException e) { return true; } }","tryCatchPattern":"try {\n    return JsonPath.parse(json).read(\"$.items[?(@.nickname == null || @.nickname == '')]\");\n} catch (InvalidPathException e) {\n    return Collections.emptyList();\n}","preventionTips":["Decide explicitly whether optional fields are omitted or set to placeholders","Write filters covering both undefined and default-value cases","Keep schema stable across versions to avoid undefined/present drift"],"tags":["jsonpath","filter","type-mismatch","undefined-node"],"backgroundTag":"type-mismatch","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"}