Revision: 1276
          http://stripes.svn.sourceforge.net/stripes/?rev=1276&view=rev
Author:   bengunter
Date:     2010-09-24 17:05:28 +0000 (Fri, 24 Sep 2010)

Log Message:
-----------
Applied fix for STS-759 from 1.5.x branch.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
    trunk/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java

Modified: trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java     
2010-09-24 16:56:41 UTC (rev 1275)
+++ trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java     
2010-09-24 17:05:28 UTC (rev 1276)
@@ -110,7 +110,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);
     }
@@ -480,6 +480,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: trunk/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java
===================================================================
--- trunk/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java   
2010-09-24 16:56:41 UTC (rev 1275)
+++ trunk/tests/src/net/sourceforge/stripes/util/ReflectUtilTest.java   
2010-09-24 17:05:28 UTC (rev 1276)
@@ -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