commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r800638 - in /commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/LazyDynaList.java test/org/apache/commons/beanutils/LazyDynaListTestCase.java
Date Tue, 04 Aug 2009 00:23:42 GMT
Author: niallp
Date: Tue Aug  4 00:23:41 2009
New Revision: 800638

URL: http://svn.apache.org/viewvc?rev=800638&view=rev
Log:
BEANUTILS-300 Fix NullPointerExceptions in LazyDynaList

Modified:
    commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaList.java
    commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaListTestCase.java

Modified: commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaList.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaList.java?rev=800638&r1=800637&r2=800638&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaList.java
(original)
+++ commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaList.java
Tue Aug  4 00:23:41 2009
@@ -503,7 +503,8 @@
             throw new IllegalArgumentException("Element Type is missing");
         }
 
-        if (size() > 0) {
+        boolean changeType = (this.elementType != null && !this.elementType.equals(elementType));
+        if (changeType && size() > 0) {
             throw new IllegalStateException("Element Type cannot be reset");
         }
 
@@ -634,18 +635,17 @@
             }
 
             // Get DynaClass (restore WrapDynaClass lost in serialization)
-            DynaClass dynaClass = (elementDynaClass == null) ? wrapDynaClass : elementDynaClass;
-            if (dynaClass == null) {
+            if (getDynaClass() == null) {
                 setElementType(elementType);
             }
                          
             // Create a new DynaBean            
             try {
-                dynaBean = dynaClass.newInstance();
+                dynaBean = getDynaClass().newInstance();
                 newDynaBeanType = dynaBean.getClass();
             } catch (Exception e) {
                 throw new IllegalArgumentException("Error creating DynaBean: " 
-                              + dynaClass.getClass().getName() 
+                              + getDynaClass().getClass().getName() 
                               + " - " + e);
             }
 
@@ -675,7 +675,7 @@
 
         // Check the new element type, matches all the 
         // other elements in the List
-        if (newElementType != elementType) {
+        if (elementType != null && !newElementType.equals(elementType)) {
             throw new IllegalArgumentException("Element Type "  + newElementType 
                        + " doesn't match other elements " + elementType);
         }
@@ -683,5 +683,11 @@
         return dynaBean;
         
     }
-    
+
+    /**
+     * Return the DynaClass.
+     */
+    private DynaClass getDynaClass() {
+        return (elementDynaClass == null ? wrapDynaClass : elementDynaClass);
+    }
 }

Modified: commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaListTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaListTestCase.java?rev=800638&r1=800637&r2=800638&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaListTestCase.java
(original)
+++ commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaListTestCase.java
Tue Aug  4 00:23:41 2009
@@ -219,6 +219,13 @@
 
     }
 
+    /**
+     * Test adding a map to List with no type set.
+     */
+    public void testNullType() {
+        LazyDynaList lazyList = new LazyDynaList();
+        lazyList.add(new HashMap());
+    }
 
     /**
      * Test DynaBean Create
@@ -519,6 +526,9 @@
         target = null;
         bean = null;
 
+        // Test BEANUTILS-300
+        result.add(null);
+
         // Confirm property value
         bean = (WrapDynaBean)result.get(0);
         assertEquals("post-serialize check", "value1", bean.get("stringProperty"));



Mime
View raw message