From 4d2a398cbc0f93842c5e427e4eb71fa3751e35fc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 8 Apr 2010 12:15:18 +0000 Subject: [PATCH] call setAccessible for public final field too (SPR-7078) --- ...wiredAnnotationBeanPostProcessorTests.java | 4 ++-- .../springframework/util/ReflectionUtils.java | 23 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java index 0e9d4424b8..b2967a33aa 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -954,7 +954,7 @@ public final class AutowiredAnnotationBeanPostProcessorTests { public static class ExtendedResourceInjectionBean extends ResourceInjectionBean { @Autowired - protected ITestBean testBean3; + public final ITestBean testBean3 = null; private T nestedTestBean; diff --git a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java index 843398c2cf..c47c02b51b 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -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"); * you may not use this file except in compliance with the License. @@ -42,9 +42,8 @@ import java.util.List; public abstract class ReflectionUtils { /** - * Attempt to find a {@link Field field} on the supplied {@link Class} with - * the supplied name. Searches all superclasses up to - * {@link Object}. + * Attempt to find a {@link Field field} on the supplied {@link Class} with the + * supplied name. Searches all superclasses up to {@link Object}. * @param clazz the class to introspect * @param name the name of the field * @return the corresponding Field object, or null if not found @@ -54,9 +53,9 @@ public abstract class ReflectionUtils { } /** - * Attempt to find a {@link Field field} on the supplied {@link Class} with - * the supplied name and/or {@link Class type}. Searches all - * superclasses up to {@link Object}. + * Attempt to find a {@link Field field} on the supplied {@link Class} with the + * supplied name and/or {@link Class type}. Searches all superclasses + * up to {@link Object}. * @param clazz the class to introspect * @param name the name of the field (may be null if type is specified) * @param type the type of the field (may be null if name is specified) @@ -115,8 +114,8 @@ public abstract class ReflectionUtils { } catch (IllegalAccessException ex) { handleReflectionException(ex); - throw new IllegalStateException("Unexpected reflection exception - " + ex.getClass().getName() + ": " - + ex.getMessage()); + throw new IllegalStateException( + "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); } } @@ -382,8 +381,8 @@ public abstract class ReflectionUtils { * @see java.lang.reflect.Field#setAccessible */ public static void makeAccessible(Field field) { - if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())) - && !field.isAccessible()) { + if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || + Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { field.setAccessible(true); } } @@ -572,6 +571,7 @@ public abstract class ReflectionUtils { boolean matches(Method method); } + /** * 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. */