Call setAccessible only once

In the getField method, due to recursion, the field.setAccessible was called a number of times equal to the number of level to go up the hierarchy to find the field
This commit is contained in:
Arnaud Tournier
2015-12-11 16:32:32 +01:00
parent 4f00182efc
commit 5b4b8a3320
@@ -7,10 +7,10 @@ public class Reflections {
public static Field getField(final Class<?> clazz, final String fieldName) throws Exception {
Field field = clazz.getDeclaredField(fieldName);
if (field == null && clazz.getSuperclass() != null) {
if (field != null)
field.setAccessible(true);
else if (clazz.getSuperclass() != null)
field = getField(clazz.getSuperclass(), fieldName);
}
field.setAccessible(true);
return field;
}