From b4f29862b1f870e8eff6faa46b11a7490e4de784 Mon Sep 17 00:00:00 2001 From: Rob Harrop Date: Wed, 16 Sep 2009 09:53:14 +0000 Subject: [PATCH] [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 --- .../org/springframework/beans/BeanUtils.java | 2 +- .../beans/BeanWrapperImpl.java | 2 +- .../beans/CachedIntrospectionResults.java | 6 +++ .../springframework/beans/BeanUtilsTests.java | 47 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/BeanUtils.java b/org.springframework.beans/src/main/java/org/springframework/beans/BeanUtils.java index fc9b7ce2f9e..1554eef21ec 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -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(); } /** diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java index 1fc2823f0b8..d17ad0cd84e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java @@ -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 { diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index 8e9798f8b7f..191d5fa1dd6 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -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 descriptorCollection = this.propertyDescriptorCache.values(); + return descriptorCollection.toArray(new PropertyDescriptor[descriptorCollection.size()]); + } + } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/BeanUtilsTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/BeanUtilsTests.java index bae404235d7..a8abdd95f29 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/BeanUtilsTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/BeanUtilsTests.java @@ -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 getKey(); + + void setKey(V value); + + V getValue(); + + void setValue(V value); + } + + private static class Bean implements MapEntry { + + 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; + } + } + }