CachedIntrospectionResults completely traverses interface hierarchy
Issue: SPR-16978
This commit is contained in:
parent
81cb740e0a
commit
bf5fe46fa9
|
@ -297,20 +297,10 @@ public final class CachedIntrospectionResults {
|
||||||
|
|
||||||
// Explicitly check implemented interfaces for setter/getter methods as well,
|
// Explicitly check implemented interfaces for setter/getter methods as well,
|
||||||
// in particular for Java 8 default methods...
|
// in particular for Java 8 default methods...
|
||||||
Class<?> clazz = beanClass;
|
Class<?> currClass = beanClass;
|
||||||
while (clazz != null && clazz != Object.class) {
|
while (currClass != null && currClass != Object.class) {
|
||||||
Class<?>[] ifcs = clazz.getInterfaces();
|
introspectInterfaces(beanClass, currClass);
|
||||||
for (Class<?> ifc : ifcs) {
|
currClass = currClass.getSuperclass();
|
||||||
if (!ClassUtils.isJavaLanguageInterface(ifc)) {
|
|
||||||
for (PropertyDescriptor pd : getBeanInfo(ifc).getPropertyDescriptors()) {
|
|
||||||
if (!this.propertyDescriptorCache.containsKey(pd.getName())) {
|
|
||||||
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
|
|
||||||
this.propertyDescriptorCache.put(pd.getName(), pd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clazz = clazz.getSuperclass();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.typeDescriptorCache = new ConcurrentReferenceHashMap<>();
|
this.typeDescriptorCache = new ConcurrentReferenceHashMap<>();
|
||||||
|
@ -320,6 +310,24 @@ public final class CachedIntrospectionResults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void introspectInterfaces(Class<?> beanClass, Class<?> currClass) throws IntrospectionException {
|
||||||
|
for (Class<?> ifc : currClass.getInterfaces()) {
|
||||||
|
if (!ClassUtils.isJavaLanguageInterface(ifc)) {
|
||||||
|
for (PropertyDescriptor pd : getBeanInfo(ifc).getPropertyDescriptors()) {
|
||||||
|
PropertyDescriptor existingPd = this.propertyDescriptorCache.get(pd.getName());
|
||||||
|
if (existingPd == null ||
|
||||||
|
(existingPd.getReadMethod() == null && pd.getReadMethod() != null)) {
|
||||||
|
// GenericTypeAwarePropertyDescriptor leniently resolves a set* write method
|
||||||
|
// against a declared read method, so we prefer read method descriptors here.
|
||||||
|
pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd);
|
||||||
|
this.propertyDescriptorCache.put(pd.getName(), pd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
introspectInterfaces(ifc, ifc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BeanInfo getBeanInfo() {
|
BeanInfo getBeanInfo() {
|
||||||
return this.beanInfo;
|
return this.beanInfo;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 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.
|
||||||
|
@ -49,7 +49,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||||
GetterBean target = new GetterBean();
|
GetterBean target = new GetterBean();
|
||||||
BeanWrapper accessor = createAccessor(target);
|
BeanWrapper accessor = createAccessor(target);
|
||||||
accessor.setPropertyValue("name", "tom");
|
accessor.setPropertyValue("name", "tom");
|
||||||
assertTrue("Set name to tom", target.getName().equals("tom"));
|
assertEquals("tom", target.getAliasedName());
|
||||||
|
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -58,7 +59,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||||
BeanWrapper accessor = createAccessor(target);
|
BeanWrapper accessor = createAccessor(target);
|
||||||
accessor.setExtractOldValueForEditor(true); // This will call the getter
|
accessor.setExtractOldValueForEditor(true); // This will call the getter
|
||||||
accessor.setPropertyValue("name", "tom");
|
accessor.setPropertyValue("name", "tom");
|
||||||
assertTrue("Set name to tom", target.getName().equals("tom"));
|
assertEquals("tom", target.getAliasedName());
|
||||||
|
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,7 +68,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||||
GetterBean target = new GetterBean();
|
GetterBean target = new GetterBean();
|
||||||
BeanWrapper accessor = createAccessor(target);
|
BeanWrapper accessor = createAccessor(target);
|
||||||
accessor.setPropertyValue("aliasedName", "tom");
|
accessor.setPropertyValue("aliasedName", "tom");
|
||||||
assertTrue("Set name to tom", target.getAliasedName().equals("tom"));
|
assertEquals("tom", target.getAliasedName());
|
||||||
|
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -216,23 +219,27 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
private interface BaseProperty {
|
||||||
private interface AliasedProperty {
|
|
||||||
|
|
||||||
default void setAliasedName(String name) {
|
|
||||||
setName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
default String getAliasedName() {
|
default String getAliasedName() {
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setName(String name);
|
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private interface AliasedProperty extends BaseProperty {
|
||||||
|
|
||||||
|
default void setAliasedName(String name) {
|
||||||
|
setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setName(String name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class GetterBean implements AliasedProperty {
|
private static class GetterBean implements AliasedProperty {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue