harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r998628 - in /harmony/enhanced/java/trunk/classlib/modules/beans/src: main/java/java/beans/StandardBeanInfo.java test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Date Sun, 19 Sep 2010 10:19:57 GMT
Author: zhoukevin
Date: Sun Sep 19 10:19:56 2010
New Revision: 998628

URL: http://svn.apache.org/viewvc?rev=998628&view=rev
Log:
This patch fixes 2 defects [1] [2] in Beans module caused by java.beans.StandardBeanInfo class.
[1] If a bean class has "public boolean isProperty(int)" and "public boolean getProperty(int)"
methods, RI takes getProperty(int) as read method of this "property", while HARMONY takes
isProperty(int) method
[2] If a bean class has "public boolean isProperty(int)" and "public void setProperty(int,
boolean)" methods, HARMONY fails to find this "property" while RI finds it and only regards
setProperty(int, boolean) as its write method.
Moreover, this patch includes 17 test cases to reflect those problems.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
    harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/StandardBeanInfo.java?rev=998628&r1=998627&r2=998628&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/StandardBeanInfo.java
Sun Sep 19 10:19:56 2010
@@ -985,24 +985,28 @@ class StandardBeanInfo extends SimpleBea
             }
 
             // retrieve getters
+            Class<?>[] paramTypes = null;
+            String methodName = null;
             for (Method getter : getters) {
+                paramTypes = getter.getParameterTypes();
+                methodName = getter.getName();
                 // checks if it's a normal getter
-                if (getter.getParameterTypes() == null
-                        || getter.getParameterTypes().length == 0) {
+                if (paramTypes == null || paramTypes.length == 0) {
                     // normal getter found
                     if (normalGetter == null
-                            || getter.getName().startsWith(PREFIX_IS)) {
+                            || methodName.startsWith(PREFIX_IS)) {
                         normalGetter = getter;
                     }
                 }
 
                 // checks if it's an indexed getter
-                if (getter.getParameterTypes() != null
-                        && getter.getParameterTypes().length == 1
-                        && getter.getParameterTypes()[0] == int.class) {
+                if (paramTypes != null && paramTypes.length == 1
+                        && paramTypes[0] == int.class) {
                     // indexed getter found
                     if (indexedGetter == null
-                            || getter.getName().startsWith(PREFIX_IS)) {
+                            || methodName.startsWith(PREFIX_GET)
+                            || (methodName.startsWith(PREFIX_IS) && !indexedGetter
+                                    .getName().startsWith(PREFIX_GET))) {
                         indexedGetter = getter;
                     }
                 }
@@ -1251,6 +1255,12 @@ class StandardBeanInfo extends SimpleBea
                     && (indexedGetter != null || indexedSetter != null)) {
                 if (indexedGetter != null
                         && indexedGetter.getName().startsWith(PREFIX_IS)) {
+                    if (indexedSetter != null) {
+                        table.put(STR_INDEXED, STR_VALID);
+                        table.put(STR_INDEXED + PREFIX_SET, indexedSetter);
+                        table.put(STR_INDEXED + STR_PROPERTY_TYPE,
+                                indexedPropType);
+                    }
                     continue;
                 }
                 table.put(STR_INDEXED, STR_VALID);

Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?rev=998628&r1=998627&r2=998628&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
Sun Sep 19 10:19:56 2010
@@ -4117,6 +4117,512 @@ public class IntrospectorTest extends Te
         }
     }
 
+    public class MixedSimpleClass45 {
+        public boolean isList(int index) {
+            return true;
+        }
+    }
+
+    public void test_MixedSimpleClass45() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass45.class);
+        assertEquals(1, beanInfo.getPropertyDescriptors().length);
+    }
+
+    public class MixedSimpleClass46 {
+        public boolean getList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+    }
+
+    public void test_MixedSimpleClass46() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass46.class);
+        Method getter = MixedSimpleClass46.class.getMethod("getList",
+                new Class<?>[] {});
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass47 {
+        public boolean isList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+    }
+
+    public void test_MixedSimpleClass47() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass47.class);
+        Method getter = MixedSimpleClass47.class.getMethod("isList",
+                new Class<?>[] {});
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass48 {
+        public boolean getList(int index) {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+    }
+
+    public void test_MixedSimpleClass48() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass48.class);
+        Method getter = MixedSimpleClass48.class.getMethod("getList",
+                new Class<?>[] { int.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertEquals(getter,
+                        ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass49 {
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass49() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass49.class);
+        Method setter = MixedSimpleClass49.class.getMethod("setList",
+                new Class<?>[] { boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertEquals(setter, pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass50 {
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(int index, boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass50() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass50.class);
+        Method setter = MixedSimpleClass50.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass51 {
+        public boolean getList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass51() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass51.class);
+        Method getter = MixedSimpleClass51.class.getMethod("getList",
+                new Class<?>[] {});
+        Method setter = MixedSimpleClass51.class.getMethod("setList",
+                new Class<?>[] { boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertEquals(setter, pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass52 {
+        public boolean getList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(int index, boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass52() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass52.class);
+        Method setter = MixedSimpleClass52.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass53 {
+        public boolean isList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass53() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass53.class);
+        Method getter = MixedSimpleClass53.class.getMethod("isList",
+                new Class<?>[] {});
+        Method setter = MixedSimpleClass53.class.getMethod("setList",
+                new Class<?>[] { boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertEquals(setter, pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass54 {
+        public boolean isList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(int index, boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass54() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass54.class);
+        Method setter = MixedSimpleClass54.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass55 {
+        public boolean getList(int index) {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass55() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass55.class);
+        Method getter = MixedSimpleClass55.class.getMethod("getList",
+                new Class<?>[] { int.class });
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertEquals(getter,
+                        ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass56 {
+        public boolean getList(int index) {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(int index, boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass56() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass56.class);
+        Method getter = MixedSimpleClass56.class.getMethod("getList",
+                new Class<?>[] { int.class });
+        Method setter = MixedSimpleClass56.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertEquals(getter,
+                        ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass57 {
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+
+        }
+
+        public void setList(int index, boolean bool) {
+        }
+    }
+
+    public void test_MixedSimpleClass57() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass57.class);
+        Method setter = MixedSimpleClass57.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertNull(((IndexedPropertyDescriptor) pd)
+                        .getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass58 {
+        public boolean getList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+
+        public void setList(int index, boolean bool) {
+
+        }
+    }
+
+    public void test_MixedSimpleClass58() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass58.class);
+        Method getter = MixedSimpleClass58.class.getMethod("getList",
+                new Class<?>[] {});
+        Method setter = MixedSimpleClass58.class.getMethod("setList",
+                new Class<?>[] { boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertEquals(setter, pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass59 {
+        public boolean isList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+
+        public void setList(int index, boolean bool) {
+
+        }
+    }
+
+    public void test_MixedSimpleClass59() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass59.class);
+        Method getter = MixedSimpleClass59.class.getMethod("isList",
+                new Class<?>[] {});
+        Method setter = MixedSimpleClass59.class.getMethod("setList",
+                new Class<?>[] { boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertEquals(getter, pd.getReadMethod());
+                assertEquals(setter, pd.getWriteMethod());
+                assertFalse(pd instanceof IndexedPropertyDescriptor);
+            }
+        }
+    }
+
+    public class MixedSimpleClass60 {
+        public boolean getList(int index) {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+
+        public void setList(int index, boolean bool) {
+
+        }
+    }
+
+    public void test_MixedSimpleClass60() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass60.class);
+        Method getter = MixedSimpleClass60.class.getMethod("getList",
+                new Class<?>[] { int.class });
+        Method setter = MixedSimpleClass60.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertEquals(getter,
+                        ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
+    public class MixedSimpleClass61 {
+        public boolean getList() {
+            return true;
+        }
+
+        public boolean getList(int index) {
+            return true;
+        }
+
+        public boolean isList() {
+            return true;
+        }
+
+        public boolean isList(int index) {
+            return true;
+        }
+
+        public void setList(boolean bool) {
+        }
+
+        public void setList(int index, boolean bool) {
+
+        }
+    }
+
+    public void test_MixedSimpleClass61() throws Exception {
+        BeanInfo beanInfo = Introspector.getBeanInfo(MixedSimpleClass61.class);
+        Method getter = MixedSimpleClass61.class.getMethod("getList",
+                new Class<?>[] { int.class });
+        Method setter = MixedSimpleClass61.class.getMethod("setList",
+                new Class<?>[] { int.class, boolean.class });
+        assertEquals(2, beanInfo.getPropertyDescriptors().length);
+        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
+            if (propertyName.equals(pd.getName())) {
+                assertNull(pd.getReadMethod());
+                assertNull(pd.getWriteMethod());
+                assertTrue(pd instanceof IndexedPropertyDescriptor);
+                assertEquals(getter,
+                        ((IndexedPropertyDescriptor) pd).getIndexedReadMethod());
+                assertEquals(setter,
+                        ((IndexedPropertyDescriptor) pd)
+                                .getIndexedWriteMethod());
+            }
+        }
+    }
+
     public class MixedExtendClass1 extends MixedSimpleClass4 {
         public void setList(Object a) {
 



Mime
View raw message