diff --git a/src/main/java/com/alibaba/fastjson/JSONPath.java b/src/main/java/com/alibaba/fastjson/JSONPath.java index a8cc592d93..a7401d6225 100644 --- a/src/main/java/com/alibaba/fastjson/JSONPath.java +++ b/src/main/java/com/alibaba/fastjson/JSONPath.java @@ -3853,6 +3853,9 @@ protected Object getPropertyValue(Object currentObject, String propertyName, lon // skip } } + if (currentObject == null) { + return null; + } if (currentObject instanceof Map) { Map map = (Map) currentObject; diff --git a/src/test/java/com/alibaba/fastjson/jsonpath/issue3962/TestIssue3962.java b/src/test/java/com/alibaba/fastjson/jsonpath/issue3962/TestIssue3962.java new file mode 100644 index 0000000000..b235c13469 --- /dev/null +++ b/src/test/java/com/alibaba/fastjson/jsonpath/issue3962/TestIssue3962.java @@ -0,0 +1,15 @@ +package com.alibaba.fastjson.jsonpath.issue3962; + +import com.alibaba.fastjson.JSONPath; +import org.junit.Assert; +import org.junit.Test; + +public class TestIssue3962 { + + @Test + public void testIssue3962() { + Object val = JSONPath.eval("{\"a\": {\"b\": \"\"}}", "$.a.b.c"); + Assert.assertNull(val); + } + +}