I think I have found a bug regarding the
mappedPropertyType in class MappedPropertyDescriptor.
The value of the mappedPropertyType will always be
String.class regardless of the type of the
corresponding property (at least if the property has a
setter).

I have attached a patch, and also added a test case to
demonstrate the bug.

- Jan Sorensen

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
Index: MappedPropertyDescriptor.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v
retrieving revision 1.1
diff -u -r1.1 MappedPropertyDescriptor.java
--- MappedPropertyDescriptor.java       2001/08/21 21:59:02     1.1
+++ MappedPropertyDescriptor.java       2001/08/27 09:28:10
@@ -331,7 +331,7 @@
                     throw new IntrospectionException
                         ("type mismatch between mapped read and write methods");
                 }
-                mappedPropertyType = params[0];
+                mappedPropertyType = params[1];
             }
         } catch (IntrospectionException ex) {
             throw ex;
Index: TestBean.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v
retrieving revision 1.3
diff -u -r1.3 TestBean.java
--- TestBean.java       2001/08/21 21:59:02     1.3
+++ TestBean.java       2001/08/27 09:35:14
@@ -210,6 +210,26 @@
         mappedProperty.put(key, value);
     }
 
+    /**
+     * A mapped property that has String keys and int values.
+     */
+    private HashMap mappedIntProperty = null;
+
+    public int getMappedIntProperty(String key) {
+        // Create the map the very first time
+        if (mappedIntProperty == null) {
+            mappedIntProperty = new HashMap();
+            mappedIntProperty.put("One", new Integer(1));
+            mappedIntProperty.put("Two", new Integer(2));
+        }
+        Integer x = (Integer)mappedIntProperty.get(key);
+        return x == null ? 0 : x.intValue();
+    }
+
+    public void setMappedIntProperty(String key, int value) {
+        mappedIntProperty.put(key, new Integer(value));
+    }
+
 
     /**
      * A nested reference to another test bean (populated as needed).
Index: PropertyUtilsTestCase.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java,v
retrieving revision 1.9
diff -u -r1.9 PropertyUtilsTestCase.java
--- PropertyUtilsTestCase.java  2001/08/21 23:05:08     1.9
+++ PropertyUtilsTestCase.java  2001/08/27 09:38:36
@@ -2899,5 +2899,20 @@
 
     }
 
+    /**
+     * Test the mappedPropertyType of MappedPropertyDescriptor
+     */
+    public void testMappedPropertyType() throws Exception {
+        MappedPropertyDescriptor desc;
+        
+        // Check a String property
+        desc = (MappedPropertyDescriptor)PropertyUtils.getPropertyDescriptor(bean, 
+"mappedProperty");
+        assertEquals(String.class, desc.getMappedPropertyType());
+
+        // Check an int property
+        desc = (MappedPropertyDescriptor)PropertyUtils.getPropertyDescriptor(bean, 
+"mappedIntProperty");
+        assertEquals( Integer.TYPE, desc.getMappedPropertyType());
+    
+    }
 
 }

Reply via email to