Skip to content

Commit

Permalink
fix BeanUtils#declaredFields null input error, for issue #1286
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Mar 27, 2023
1 parent f508c89 commit 48416e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/util/BeanUtils.java
Expand Up @@ -277,6 +277,10 @@ public static Field getDeclaredField(Class objectClass, String fieldName) {
* ignore static fields
*/
public static void declaredFields(Class objectClass, Consumer<Field> fieldConsumer) {
if (objectClass == null || fieldConsumer == null) {
return;
}

if (TypeUtils.isProxy(objectClass)) {
Class superclass = objectClass.getSuperclass();
declaredFields(superclass, fieldConsumer);
Expand Down
Expand Up @@ -263,4 +263,10 @@ public Void getA() {
return null;
}
}

@Test
public void declaredFieldsNull() {
BeanUtils.declaredFields(null, o -> {});
BeanUtils.declaredFields(Object.class, null);
}
}

0 comments on commit 48416e2

Please sign in to comment.