Moving AccessibleObject.setAccessible to where the fields are obtained by reflection.

This commit is contained in:
Inderjeet Singh 2011-03-24 22:16:25 +00:00
parent 0adf7f5e17
commit 4a58dc3e2a

View File

@ -63,7 +63,6 @@ final class ReflectingFieldNavigator {
private void navigateClassFields(Object obj, Type objType,
Class<?> classInInheritanceHierarchyForObj, Visitor visitor) {
Field[] fields = getFields(classInInheritanceHierarchyForObj);
AccessibleObject.setAccessible(fields, true);
for (Field f : fields) {
FieldAttributes fieldAttributes = new FieldAttributes(classInInheritanceHierarchyForObj, f);
if (exclusionStrategy.shouldSkipField(fieldAttributes)
@ -87,6 +86,7 @@ final class ReflectingFieldNavigator {
Field[] fields = fieldsCache.get(clazz);
if (fields == null) {
fields = clazz.getDeclaredFields();
AccessibleObject.setAccessible(fields, true);
fieldsCache.put(clazz, fields);
}
return fields;