Revision: 1275
          http://stripes.svn.sourceforge.net/stripes/?rev=1275&view=rev
Author:   bengunter
Date:     2010-09-24 16:56:41 +0000 (Fri, 24 Sep 2010)

Log Message:
-----------
Fixed STS-759: Setter methods fail when a bean overrides a method with a 
subclass

Modified Paths:
--------------
    branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
    branches/1.5.x/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java    
2010-09-24 15:37:41 UTC (rev 1274)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java    
2010-09-24 16:56:41 UTC (rev 1275)
@@ -121,7 +121,7 @@
      * @throws InstantiationException if no implementation type has been 
configured
      * @throws IllegalAccessException if thrown by the JVM during class 
instantiation
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({ "unchecked", "rawtypes" })
        public static <T> T getInterfaceInstance(Class<T> interfaceType)
             throws InstantiationException, IllegalAccessException {
         Class impl = getImplementingClass(interfaceType);
@@ -153,7 +153,7 @@
      * @return the Class object representing the class
      * @throws ClassNotFoundException if the class cannot be loaded
      */
-    @SuppressWarnings("unchecked") // this allows us to assign without casting
+    @SuppressWarnings("rawtypes") // this allows us to assign without casting
        public static Class findClass(String name) throws 
ClassNotFoundException {
         return Thread.currentThread().getContextClassLoader().loadClass(name);
     }
@@ -523,6 +523,19 @@
                         || (pd.getWriteMethod() != null && 
pd.getWriteMethod().isBridge())) {
                     log.debug("Working around JVM bug involving 
PropertyDescriptors ",
                             "and bridge methods for ", clazz);
+
+                    // Work around a JVM bug involving covariant return types 
from property getters
+                    if (pd.getWriteMethod() == null && pd.getReadMethod() != 
null
+                            && pd.getReadMethod().isBridge()) {
+                        try {
+                            pd = new PropertyDescriptor(pd.getName(), clazz);
+                            log.debug("Working around JVM bug 
http://bugs.sun.com/view_bug.do?bug_id=6794807";);
+                        }
+                        catch (IntrospectionException e) {
+                            // This can happen for read-only properties. 
Ignore it.
+                        }
+                    }
+
                     pd = new BridgedPropertyDescriptor(pd);
                     pds[i] = pd;
                 }

Modified: 
branches/1.5.x/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java
===================================================================
--- branches/1.5.x/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java  
2010-09-24 15:37:41 UTC (rev 1274)
+++ branches/1.5.x/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java  
2010-09-24 16:56:41 UTC (rev 1275)
@@ -41,4 +41,35 @@
         String value = (String) m.invoke(entry);
         Assert.assertEquals(value, "bar");
     }
+
+    @Test(groups = "fast")
+    public void testCovariantProperty() {
+        abstract class Base {
+            abstract Object getId();
+        }
+
+        class ROSub extends Base {
+            protected String id;
+
+            @Override
+            public String getId() {
+                return id;
+            }
+        }
+
+        class RWSub extends ROSub {
+            @SuppressWarnings("unused")
+            public void setId(String id) {
+                this.id = id;
+            }
+        }
+
+        PropertyDescriptor pd = ReflectUtil.getPropertyDescriptor(ROSub.class, 
"id");
+        Assert.assertNotNull(pd.getReadMethod(), "Read method is null");
+        Assert.assertNull(pd.getWriteMethod(), "Write method is not null");
+
+        pd = ReflectUtil.getPropertyDescriptor(RWSub.class, "id");
+        Assert.assertNotNull(pd.getReadMethod(), "Read method is null");
+        Assert.assertNotNull(pd.getWriteMethod(), "Write method is null");
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to