From e5783b1bfaf5b7494152b63092d5dd293ba6f4ce Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 15 Jan 2013 16:51:35 +0100 Subject: [PATCH] SpEL support for static finals on interfaces Issue: SPR-10125 Backport-Issue: SPR-10174 --- .../support/ReflectivePropertyAccessor.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java index 5408e6e31ce..d12b25ed1ce 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java @@ -287,7 +287,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { private Method findGetterForProperty(String propertyName, Class clazz, Object target) { Method method = findGetterForProperty(propertyName, clazz, target instanceof Class); - if(method == null && target instanceof Class) { + if (method == null && target instanceof Class) { method = findGetterForProperty(propertyName, target.getClass(), false); } return method; @@ -295,7 +295,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { private Method findSetterForProperty(String propertyName, Class clazz, Object target) { Method method = findSetterForProperty(propertyName, clazz, target instanceof Class); - if(method == null && target instanceof Class) { + if (method == null && target instanceof Class) { method = findSetterForProperty(propertyName, target.getClass(), false); } return method; @@ -303,7 +303,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { private Field findField(String name, Class clazz, Object target) { Field field = findField(name, clazz, target instanceof Class); - if(field == null && target instanceof Class) { + if (field == null && target instanceof Class) { field = findField(name, target.getClass(), false); } return field; @@ -374,6 +374,20 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { return field; } } + // We'll search superclasses and implemented interfaces explicitly, + // although it shouldn't be necessary - however, see SPR-10125. + if (clazz.getSuperclass() != null) { + Field field = findField(name, clazz.getSuperclass(), mustBeStatic); + if (field != null) { + return field; + } + } + for (Class implementedInterface : clazz.getInterfaces()) { + Field field = findField(name, implementedInterface, mustBeStatic); + if (field != null) { + return field; + } + } return null; }