Skip to content

Commit

Permalink
fix issue #2997 throws NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooper-Zhong authored and wenshao committed Oct 7, 2024
1 parent e9e4c80 commit 3ea0abc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public static boolean remove(Object root, String path) {
}

public static boolean contains(Object rootObject, String path) {
if (rootObject == null) {
return false;
}
com.alibaba.fastjson2.JSONPath jsonPath = com.alibaba.fastjson2.JSONPath.of(path);
return jsonPath.contains(rootObject);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.alibaba.fastjson.v2issues;

import com.alibaba.fastjson.JSONPath;
import org.junit.jupiter.api.Test;

public class Issue2997 {
@Test
public void testContainsNullRootObject() {
Object rootObject = null;
String path = "$.key";
JSONPath.contains(rootObject, path);
}
}

0 comments on commit 3ea0abc

Please sign in to comment.