Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A6264E2D9 for ; Sun, 24 Feb 2013 12:10:40 +0000 (UTC) Received: (qmail 29219 invoked by uid 500); 24 Feb 2013 12:10:38 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 29040 invoked by uid 500); 24 Feb 2013 12:10:38 -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 29016 invoked by uid 99); 24 Feb 2013 12:10:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 24 Feb 2013 12:10:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Sun, 24 Feb 2013 12:10:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7AC4C2388900; Sun, 24 Feb 2013 12:10:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1449465 - in /commons/proper/beanutils/trunk/src: changes/changes.xml main/java/org/apache/commons/beanutils/MethodUtils.java test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java Date: Sun, 24 Feb 2013 12:10:14 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130224121014.7AC4C2388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: britter Date: Sun Feb 24 12:10:13 2013 New Revision: 1449465 URL: http://svn.apache.org/r1449465 Log: [BEANUTILS-408] - MethodUtils.invokeMethod() throws NullPointerException when args==null Modified: commons/proper/beanutils/trunk/src/changes/changes.xml commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java Modified: commons/proper/beanutils/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/changes/changes.xml?rev=1449465&r1=1449464&r2=1449465&view=diff ============================================================================== --- commons/proper/beanutils/trunk/src/changes/changes.xml (original) +++ commons/proper/beanutils/trunk/src/changes/changes.xml Sun Feb 24 12:10:13 2013 @@ -40,6 +40,9 @@ The type attribute can be add,u + + MethodUtils.invokeMethod() throws NullPointerException when args==null + ConstructorUtils.invokeConstructor(Class klass, Object arg) throws NullPointerException when arg==null Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java?rev=1449465&r1=1449464&r2=1449465&view=diff ============================================================================== --- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java (original) +++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java Sun Feb 24 12:10:13 2013 @@ -173,7 +173,7 @@ public class MethodUtils { IllegalAccessException, InvocationTargetException { - Object[] args = {arg}; + Object[] args = toArray(arg); return invokeMethod(object, methodName, args); } @@ -309,7 +309,7 @@ public class MethodUtils { IllegalAccessException, InvocationTargetException { - Object[] args = {arg}; + Object[] args = toArray(arg); return invokeExactMethod(object, methodName, args); } @@ -487,7 +487,7 @@ public class MethodUtils { IllegalAccessException, InvocationTargetException { - Object[] args = {arg}; + Object[] args = toArray(arg); return invokeStaticMethod (objectClass, methodName, args); } @@ -626,11 +626,10 @@ public class MethodUtils { IllegalAccessException, InvocationTargetException { - Object[] args = {arg}; + Object[] args = toArray(arg); return invokeExactStaticMethod (objectClass, methodName, args); } - /** *

Invoke a static method whose parameter types match exactly the object * types.

@@ -671,6 +670,14 @@ public class MethodUtils { } + private static Object[] toArray(Object arg) { + Object[] args = {arg}; + if (arg == null) { + args = null; + } + return args; + } + /** *

Return an accessible method (that is, one that can be invoked via * reflection) with given name and a single parameter. If no such method Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java?rev=1449465&r1=1449464&r2=1449465&view=diff ============================================================================== --- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java (original) +++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java Sun Feb 24 12:10:13 2013 @@ -185,6 +185,13 @@ public class MethodUtilsTestCase extends } } + public void testInvokeExactMethodNull() throws Exception { + Object object = new Object(); + Object result = MethodUtils.invokeExactMethod(object, "toString", (Object) null); + assertEquals(object.toString(), result); + } + + /** *

Test invokeMethod. */ @@ -261,6 +268,12 @@ public class MethodUtilsTestCase extends MethodUtils.invokeExactMethod(parent, "getName", null, null); } + public void testInvokeMethodNull() throws Exception { + Object object = new Object(); + Object result = MethodUtils.invokeMethod(object, "toString", (Object) null); + assertEquals(object.toString(), result); + } + /** *

Test invokeMethod with a primitive. */ @@ -328,6 +341,17 @@ public class MethodUtilsTestCase extends assertEquals("currentCounter value", current, ((Integer) value).intValue()); } + public void testInvokeStaticMethodNull() throws Exception { + int current = TestBean.currentCounter(); + Object value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", (Object) null); + assertEquals("currentCounter value", current, ((Integer) value).intValue()); + } + + public void testInvokeExactStaticMethodNull() throws Exception { + int current = TestBean.currentCounter(); + Object value = MethodUtils.invokeExactStaticMethod(TestBean.class, "currentCounter", (Object) null); + assertEquals("currentCounter value", current, ((Integer) value).intValue()); + } /** * Simple tests for accessing static methods via invokeMethod().