harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r768309 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/java/beans/ main/java/org/apache/harmony/beans/internal/nls/ test/java/org/apache/harmony/beans/tests/java/beans/
Date Fri, 24 Apr 2009 13:37:57 GMT
Author: tellison
Date: Fri Apr 24 13:37:56 2009
New Revision: 768309

URL: http://svn.apache.org/viewvc?rev=768309&view=rev
Log:
Apply patch for HARMONY-6177 ([classlib][beans] java.beans.PropertyDescriptor(String propertyName,
Class<?> beanClass, String getterName, String setterName) sets the wrong write method)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?rev=768309&r1=768308&r2=768309&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
Fri Apr 24 13:37:56 2009
@@ -243,19 +243,28 @@
                 writeMethod = beanClass.getMethod(setterName,
                         new Class[] { getter.getReturnType() });
             } else {
-                Method[] methods = beanClass.getMethods();
-                for (Method method : methods) {
-                    if (method.getName().equals(setterName)) {
-                        if (method.getParameterTypes().length == 1) {
-                            writeMethod = method;
-                            break;
+                Class<?> clazz = beanClass;
+                Method[] methods = null;
+                while (clazz != null && writeMethod == null) {
+                    methods = clazz.getDeclaredMethods();
+                    for (Method method : methods) {
+                        if (setterName.equals(method.getName())) {
+                            if (method.getParameterTypes().length == 1) {
+                                writeMethod = method;
+                                break;
+                            }
                         }
                     }
+                    clazz = clazz.getSuperclass();
                 }
             }
         } catch (Exception e) {
             throw new IntrospectionException(e.getLocalizedMessage());
         }
+        if (writeMethod == null) {
+            throw new IntrospectionException(Messages.getString(
+                    "beans.64", setterName)); //$NON-NLS-1$
+        }
         setWriteMethod(writeMethod);
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?rev=768309&r1=768308&r2=768309&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
Fri Apr 24 13:37:56 2009
@@ -115,3 +115,4 @@
 beans.61=Indexed write method is not compatible with indexed read method
 beans.62=Cannot decide which method to call to match {0}
 beans.63=The type of element is mismatch with the type of array
+beans.64=Method not found: {0}

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java?rev=768309&r1=768308&r2=768309&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
Fri Apr 24 13:37:56 2009
@@ -877,6 +877,97 @@
         }
     }
 
+    class MockJSplitPane extends javax.swing.JSplitPane {
+
+        private static final long serialVersionUID = 3109235561744543400L;
+
+        public int getDividerLocation(int dividerLocation) {
+            return super.getDividerLocation();
+        }
+
+        public void setDividerLocation(int dividerLocation) {
+            super.setDividerLocation(dividerLocation);
+        }
+    }
+
+    public void test_setReadMethod_MockJSplitPane() throws Exception {
+        Class<?> beanClass = MockJSplitPane.class;
+        String propertyName = "dividerLocation";
+        String getterName = "getDividerLocation";
+        PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass,
+                getterName, null);
+        assertEquals(propertyName, pd.getName());
+        assertNull(pd.getWriteMethod());
+
+        Method expectedMethod = beanClass.getMethod(getterName, new Class[0]);
+        assertEquals(expectedMethod, pd.getReadMethod());
+
+        getterName = "notFoundGetter";
+        pd = new PropertyDescriptor(propertyName, beanClass, getterName, null);
+        assertEquals(propertyName, pd.getName());
+        assertNull(pd.getWriteMethod());
+        assertEquals(expectedMethod, pd.getReadMethod());
+    }
+
+    public void test_setWriteMethod_MockJSplitPane() throws Exception {
+        Class<?> beanClass = MockJSplitPane.class;
+        String propertyName = "dividerLocation";
+        String setterName = "setDividerLocation";
+        PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass,
+                null, setterName);
+        assertEquals(propertyName, pd.getName());
+        assertNull(pd.getReadMethod());
+
+        Method expectedMethod = beanClass.getMethod(setterName,
+                new Class[] { int.class });
+        assertEquals(expectedMethod, pd.getWriteMethod());
+
+        setterName = "notFoundSetter";
+        try {
+            new PropertyDescriptor(propertyName, beanClass, null, setterName);
+            fail("should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            // Expected
+        }
+    }
+
+    public void test_setRead$WriteMethod_MockJSplitPane() throws Exception {
+        Class<?> beanClass = MockJSplitPane.class;
+        String propertyName = "dividerLocation";
+        String getterName = "getDividerLocation";
+        String setterName = "setDividerLocation";
+        PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass,
+                getterName, setterName);
+        assertEquals(propertyName, pd.getName());
+        Method expectedGetterMethod = beanClass.getMethod(getterName,
+                new Class[0]);
+        assertEquals(expectedGetterMethod, pd.getReadMethod());
+
+        Method expectedSetterMethod = beanClass.getMethod(setterName,
+                new Class[] { int.class });
+        assertEquals(expectedSetterMethod, pd.getWriteMethod());
+
+        new PropertyDescriptor(propertyName, beanClass, getterName + 1,
+                setterName);
+        assertEquals(expectedGetterMethod, pd.getReadMethod());
+        assertEquals(expectedSetterMethod, pd.getWriteMethod());
+
+        try {
+            new PropertyDescriptor(propertyName, beanClass, getterName,
+                    setterName + 1);
+            fail("should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            // Expected
+        }
+        try {
+            new PropertyDescriptor(propertyName, beanClass, getterName + 1,
+                    setterName + 1);
+            fail("should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            // Expected
+        }
+    }
+
     public void testSetBound_true() throws SecurityException,
             NoSuchMethodException, IntrospectionException {
         Class<MockJavaBean> beanClass = MockJavaBean.class;



Mime
View raw message