Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fix JSONPath npe #4386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/alibaba/fastjson/JSONPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -3848,6 +3848,9 @@ protected Object getPropertyValue(Object currentObject, String propertyName, lon
if (currentObject instanceof String) {
try {
JSONObject object = (JSONObject) JSON.parse((String) currentObject, parserConfig);
if (object == null) {
return null;
}
currentObject = object;
} catch (Exception ex) {
// skip
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.alibaba.fastjson.jsonpath.issue4385;

import org.junit.Assert;
import org.junit.Test;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;

/**
* @author vdisk
*/
public class TestIssue4385 {

@Test
public void testIssue4385() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("key1", "");
Object value = JSONPath.eval(jsonObject, "$.key1.key2");
Assert.assertNull(value);
}
}