call setAccessible for public final field too (SPR-7078)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -954,7 +954,7 @@ public final class AutowiredAnnotationBeanPostProcessorTests {
|
|||||||
public static class ExtendedResourceInjectionBean<T> extends ResourceInjectionBean {
|
public static class ExtendedResourceInjectionBean<T> extends ResourceInjectionBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected ITestBean testBean3;
|
public final ITestBean testBean3 = null;
|
||||||
|
|
||||||
private T nestedTestBean;
|
private T nestedTestBean;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -42,9 +42,8 @@ import java.util.List;
|
|||||||
public abstract class ReflectionUtils {
|
public abstract class ReflectionUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to find a {@link Field field} on the supplied {@link Class} with
|
* Attempt to find a {@link Field field} on the supplied {@link Class} with the
|
||||||
* the supplied <code>name</code>. Searches all superclasses up to
|
* supplied <code>name</code>. Searches all superclasses up to {@link Object}.
|
||||||
* {@link Object}.
|
|
||||||
* @param clazz the class to introspect
|
* @param clazz the class to introspect
|
||||||
* @param name the name of the field
|
* @param name the name of the field
|
||||||
* @return the corresponding Field object, or <code>null</code> if not found
|
* @return the corresponding Field object, or <code>null</code> if not found
|
||||||
@@ -54,9 +53,9 @@ public abstract class ReflectionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to find a {@link Field field} on the supplied {@link Class} with
|
* Attempt to find a {@link Field field} on the supplied {@link Class} with the
|
||||||
* the supplied <code>name</code> and/or {@link Class type}. Searches all
|
* supplied <code>name</code> and/or {@link Class type}. Searches all superclasses
|
||||||
* superclasses up to {@link Object}.
|
* up to {@link Object}.
|
||||||
* @param clazz the class to introspect
|
* @param clazz the class to introspect
|
||||||
* @param name the name of the field (may be <code>null</code> if type is specified)
|
* @param name the name of the field (may be <code>null</code> if type is specified)
|
||||||
* @param type the type of the field (may be <code>null</code> if name is specified)
|
* @param type the type of the field (may be <code>null</code> if name is specified)
|
||||||
@@ -115,8 +114,8 @@ public abstract class ReflectionUtils {
|
|||||||
}
|
}
|
||||||
catch (IllegalAccessException ex) {
|
catch (IllegalAccessException ex) {
|
||||||
handleReflectionException(ex);
|
handleReflectionException(ex);
|
||||||
throw new IllegalStateException("Unexpected reflection exception - " + ex.getClass().getName() + ": "
|
throw new IllegalStateException(
|
||||||
+ ex.getMessage());
|
"Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,8 +381,8 @@ public abstract class ReflectionUtils {
|
|||||||
* @see java.lang.reflect.Field#setAccessible
|
* @see java.lang.reflect.Field#setAccessible
|
||||||
*/
|
*/
|
||||||
public static void makeAccessible(Field field) {
|
public static void makeAccessible(Field field) {
|
||||||
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()))
|
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) ||
|
||||||
&& !field.isAccessible()) {
|
Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -572,6 +571,7 @@ public abstract class ReflectionUtils {
|
|||||||
boolean matches(Method method);
|
boolean matches(Method method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface invoked on each field in the hierarchy.
|
* Callback interface invoked on each field in the hierarchy.
|
||||||
*/
|
*/
|
||||||
@@ -608,6 +608,7 @@ public abstract class ReflectionUtils {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre-built MethodFilter that matches all non-bridge methods.
|
* Pre-built MethodFilter that matches all non-bridge methods.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user