Skip to content

Commit

Permalink
Only get field when it is accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
jdereg committed Oct 9, 2023
1 parent 2f45ae0 commit 358503c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/main/java/com/cedarsoftware/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,15 @@ public static void getDeclaredFields(Class<?> c, Collection<Field> fields) {

for (Field field : local)
{
try
if (field.trySetAccessible())
{
field.setAccessible(true);
}
catch (Exception ignored) { }

int modifiers = field.getModifiers();
if (!Modifier.isStatic(modifiers) &&
!field.getName().startsWith("this$") &&
!Modifier.isTransient(modifiers))
{ // speed up: do not count static fields, do not go back up to enclosing object in nested case, do not consider transients
fields.add(field);
int modifiers = field.getModifiers();
if (!Modifier.isStatic(modifiers) &&
!field.getName().startsWith("this$") &&
!Modifier.isTransient(modifiers))
{ // speed up: do not count static fields, do not go back up to enclosing object in nested case, do not consider transients
fields.add(field);
}
}
}
}
Expand Down

0 comments on commit 358503c

Please sign in to comment.