From c720a56726cbd9dc0d6b41590be23d60f5c296c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=83=A0=E9=A3=9E?= <6580414+a1batross@user.noreply.gitee.com> Date: Mon, 11 Sep 2023 22:58:38 +0800 Subject: [PATCH] Fix Issue#3962 --- src/main/java/com/alibaba/fastjson/JSONPath.java | 3 +++ .../jsonpath/issue3962/TestIssue3962.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/java/com/alibaba/fastjson/jsonpath/issue3962/TestIssue3962.java 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); + } + +}