Skip to content

Commit

Permalink
fix: prevent infinite recursion in doWithFields method.
Browse files Browse the repository at this point in the history
  • Loading branch information
alidandach committed Dec 28, 2024
1 parent a2bc1de commit 4e3c90a
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,11 @@ public static void doWithFields(Class<?> clazz, FieldCallback fc) {
public static void doWithFields(Class<?> clazz, FieldCallback fc, @Nullable FieldFilter ff) {
// Keep backing up the inheritance hierarchy.
Class<?> targetClass = clazz;
Set<Class<?>> visitedClasses = new HashSet<>();
do {
if (!visitedClasses.add(targetClass)) {
break; // Avoid infinite recursion
}
Field[] fields = getDeclaredFields(targetClass);
for (Field field : fields) {
if (ff != null && !ff.matches(field)) {
Expand Down

0 comments on commit 4e3c90a

Please sign in to comment.