[SPR-6063] fixed issue with inconsistent views of PropertyDescriptors

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1900 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Rob Harrop 2009-09-16 09:53:14 +00:00
parent e46f8c044a
commit b4f29862b1
4 changed files with 55 additions and 2 deletions

View File

@ -338,7 +338,7 @@ public abstract class BeanUtils {
*/
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws BeansException {
CachedIntrospectionResults cr = CachedIntrospectionResults.forClass(clazz);
return cr.getBeanInfo().getPropertyDescriptors();
return cr.getPropertyDescriptors();
}
/**

View File

@ -275,7 +275,7 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
public PropertyDescriptor[] getPropertyDescriptors() {
return getCachedIntrospectionResults().getBeanInfo().getPropertyDescriptors();
return getCachedIntrospectionResults().getPropertyDescriptors();
}
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws BeansException {

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -268,4 +269,9 @@ public class CachedIntrospectionResults {
return this.propertyDescriptorCache.get(propertyName);
}
PropertyDescriptor[] getPropertyDescriptors() {
Collection<PropertyDescriptor> descriptorCollection = this.propertyDescriptorCache.values();
return descriptorCollection.toArray(new PropertyDescriptor[descriptorCollection.size()]);
}
}

View File

@ -249,6 +249,19 @@ public final class BeanUtilsTests {
assertSignatureEquals(desiredMethod, "doSomethingWithAMultiDimensionalArray(java.lang.String[][])");
}
@Test
public void testSPR6063() {
PropertyDescriptor[] descrs = BeanUtils.getPropertyDescriptors(Bean.class);
PropertyDescriptor keyDescr = BeanUtils.getPropertyDescriptor(Bean.class, "value");
assertEquals(String.class, keyDescr.getPropertyType());
for (PropertyDescriptor propertyDescriptor : descrs) {
if (propertyDescriptor.getName().equals(keyDescr.getName())) {
assertEquals(propertyDescriptor.getName() + " has unexpected type", keyDescr.getPropertyType(), propertyDescriptor.getPropertyType());
}
}
}
private void assertSignatureEquals(Method desiredMethod, String signature) {
assertEquals(desiredMethod, BeanUtils.resolveSignature(signature, MethodSignatureBean.class));
}
@ -330,4 +343,38 @@ public final class BeanUtilsTests {
}
}
private interface MapEntry<K, V> {
K getKey();
void setKey(V value);
V getValue();
void setValue(V value);
}
private static class Bean implements MapEntry<String, String> {
private String key;
private String value;
public String getKey() {
return key;
}
public void setKey(String aKey) {
key = aKey;
}
public String getValue() {
return value;
}
public void setValue(String aValue) {
value = aValue;
}
}
}