commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r332559 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/BeanUtilsBean.java test/org/apache/commons/beanutils/MappedPropertyTestBean.java test/org/apache/commons/beanutils/MappedPropertyTestCase.java
Date Fri, 11 Nov 2005 14:09:51 GMT
Author: niallp
Date: Fri Nov 11 06:09:42 2005
New Revision: 332559

URL: http://svn.apache.org/viewcvs?rev=332559&view=rev
Log:
Fix Bug 27965 - Writing to a mapped property requires a setter for a map, but never uses it,
reported by Dmitry Platonoff

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java?rev=332559&r1=332558&r2=332559&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
Fri Nov 11 06:09:42 2005
@@ -984,6 +984,14 @@
                 }
                 type = ((IndexedPropertyDescriptor) descriptor).
                     getIndexedPropertyType();
+            } else if (key != null) {
+                if (descriptor.getReadMethod() == null) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Skipping read-only property");
+                    }
+                    return; // Read-only, skip this property setter
+                }
+                type = (value == null) ? Object.class : value.getClass();
             } else {
                 if (descriptor.getWriteMethod() == null) {
                     if (log.isDebugEnabled()) {

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java?rev=332559&r1=332558&r2=332559&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestBean.java
Fri Nov 11 06:09:42 2005
@@ -30,6 +30,8 @@
 public class MappedPropertyTestBean {
 
     private Map map = new HashMap();
+    private Map myMap = new HashMap();
+
 
     // -------------------------------------------------------------- Properties
 
@@ -75,6 +77,9 @@
 
     public String getInvalidGetter(String key, String other) {
         return (String) map.get(key);
+    }
+    public Map getMyMap() {
+        return myMap;
     }
 
     public void setInvalidGetter(String key, String value) {	

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java?rev=332559&r1=332558&r2=332559&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/MappedPropertyTestCase.java
Fri Nov 11 06:09:42 2005
@@ -204,6 +204,23 @@
         }
     }
 
+    /**
+     * Test Mpa getter
+     */
+    public void testMapGetter() {
+        MappedPropertyTestBean bean = new MappedPropertyTestBean();
+        Class clazz = MappedPropertyTestBean.class;
+        String property = "myMap";
+        try {
+            String testValue = "test value";
+            String testKey   = "testKey";
+            BeanUtils.setProperty(bean, "myMap("+testKey+")", "test value");
+            assertEquals("Map getter", testValue, bean.getMyMap().get(testKey));
+        } catch (Exception ex) {
+            fail("Test set mapped property failed: " + ex);
+        }
+    }
+
 
     /**
      * Test property with any two args



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message