Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 96579 invoked from network); 4 Aug 2009 00:23:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Aug 2009 00:23:59 -0000 Received: (qmail 42428 invoked by uid 500); 4 Aug 2009 00:24:04 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 42331 invoked by uid 500); 4 Aug 2009 00:24:04 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 42322 invoked by uid 99); 4 Aug 2009 00:24:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Aug 2009 00:24:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Aug 2009 00:24:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 54DA72388891; Tue, 4 Aug 2009 00:23:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090804002342.54DA72388891@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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"));