From ef143d363ecd366f698fef2e3a019d39f3f569a8 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 13 Feb 2012 13:51:43 +0100 Subject: [PATCH] Polish ExtendedBeanInfo and tests ExtendedBeanInfo - Reduce log messages from warn to debug - Remove now-incorrect comment indicating underlying property descriptors are never modified (they actually are as of SPR-8806) ExtendedBeanInfoTests - Consolidate SPR-8949 tests - Eliminate compiler warnings Issue: SPR-8949, SPR-8806 --- .../beans/ExtendedBeanInfo.java | 10 +---- .../beans/ExtendedBeanInfoTests.java | 41 ++++++++++++------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index c2551dc284..3b0dd4ccbd 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -75,12 +75,6 @@ class ExtendedBeanInfo implements BeanInfo { public ExtendedBeanInfo(BeanInfo delegate) throws IntrospectionException { this.delegate = delegate; - // PropertyDescriptor instances from the delegate object are never added directly, but always - // copied to the local collection of #propertyDescriptors and returned by calls to - // #getPropertyDescriptors(). this algorithm iterates through all methods (method descriptors) - // in the wrapped BeanInfo object, copying any existing PropertyDescriptor or creating a new - // one for any non-standard setter methods found. - ALL_METHODS: for (MethodDescriptor md : delegate.getMethodDescriptors()) { Method method = md.getMethod(); @@ -282,7 +276,7 @@ class ExtendedBeanInfo implements BeanInfo { } this.propertyDescriptors.add(pd); } catch (IntrospectionException ex) { - logger.warn(format("Could not create new PropertyDescriptor for readMethod [%s] writeMethod [%s] " + + logger.debug(format("Could not create new PropertyDescriptor for readMethod [%s] writeMethod [%s] " + "indexedReadMethod [%s] indexedWriteMethod [%s] for property [%s]. Reason: %s", readMethod, writeMethod, indexedReadMethod, indexedWriteMethod, propertyName, ex.getMessage())); // suppress exception and attempt to continue @@ -293,7 +287,7 @@ class ExtendedBeanInfo implements BeanInfo { try { pd.setWriteMethod(writeMethod); } catch (IntrospectionException ex) { - logger.warn(format("Could not add write method [%s] for property [%s]. Reason: %s", + logger.debug(format("Could not add write method [%s] for property [%s]. Reason: %s", writeMethod, propertyName, ex.getMessage())); // fall through -> add property descriptor as best we can } diff --git a/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java index 0dfea93a54..8111fdb237 100644 --- a/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java @@ -698,17 +698,31 @@ public class ExtendedBeanInfoTests { } - /** - * java.beans.Introspector returns the "wrong" declaring class for overridden read - * methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding - * method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)} - * helps out here, and is now put into use in ExtendedBeanInfo as well - */ @Test - public void demonstrateCauseSpr8949() throws IntrospectionException { - BeanInfo info = Introspector.getBeanInfo(B.class); + public void cornerSpr8949() throws IntrospectionException { + class A { + @SuppressWarnings("unused") + public boolean isTargetMethod() { + return false; + } + } - for (PropertyDescriptor pd : info.getPropertyDescriptors()) { + class B extends A { + @Override + public boolean isTargetMethod() { + return false; + } + } + + BeanInfo bi = Introspector.getBeanInfo(B.class); + + /* first, demonstrate the 'problem': + * java.beans.Introspector returns the "wrong" declaring class for overridden read + * methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding + * method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)} + * helps out here, and is now put into use in ExtendedBeanInfo as well + */ + for (PropertyDescriptor pd : bi.getPropertyDescriptors()) { if ("targetMethod".equals(pd.getName())) { Method readMethod = pd.getReadMethod(); assertTrue(readMethod.getDeclaringClass().equals(A.class)); // we expected B! @@ -717,11 +731,8 @@ public class ExtendedBeanInfoTests { assertTrue(msReadMethod.getDeclaringClass().equals(B.class)); // and now we get it. } } - } - @Test - public void cornerSpr8949() throws IntrospectionException { - BeanInfo bi = Introspector.getBeanInfo(B.class); + // and now demonstrate that we've indeed fixed the problem ExtendedBeanInfo ebi = new ExtendedBeanInfo(bi); assertThat(hasReadMethodForProperty(bi, "targetMethod"), is(true)); @@ -731,13 +742,13 @@ public class ExtendedBeanInfoTests { assertThat(hasWriteMethodForProperty(ebi, "targetMethod"), is(false)); } - static class A { + static class X { public boolean isTargetMethod() { return false; } } - static class B extends A { + static class Y extends X { @Override public boolean isTargetMethod() { return false;