commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1369102 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/reflect/MethodUtils.java test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Date Fri, 03 Aug 2012 17:17:19 GMT
Author: mbenson
Date: Fri Aug  3 17:17:18 2012
New Revision: 1369102

URL: http://svn.apache.org/viewvc?rev=1369102&view=rev
Log:
[LANG-814] MethodUtils.invoke*(*, Object... args) variants cannot handle null values

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java?rev=1369102&r1=1369101&r2=1369102&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
Fri Aug  3 17:17:18 2012
@@ -86,11 +86,7 @@ public class MethodUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        int arguments = args.length;
-        Class<?>[] parameterTypes = new Class[arguments];
-        for (int i = 0; i < arguments; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?>[] parameterTypes = ClassUtils.toClass(args);
         return invokeMethod(object, methodName, args, parameterTypes);
     }
 
@@ -157,11 +153,7 @@ public class MethodUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        int arguments = args.length;
-        Class<?>[] parameterTypes = new Class[arguments];
-        for (int i = 0; i < arguments; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?>[] parameterTypes = ClassUtils.toClass(args);
         return invokeExactMethod(object, methodName, args, parameterTypes);
     }
 
@@ -271,11 +263,7 @@ public class MethodUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        int arguments = args.length;
-        Class<?>[] parameterTypes = new Class[arguments];
-        for (int i = 0; i < arguments; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?>[] parameterTypes = ClassUtils.toClass(args);
         return invokeStaticMethod(cls, methodName, args, parameterTypes);
     }
 
@@ -344,11 +332,7 @@ public class MethodUtils {
         if (args == null) {
             args = ArrayUtils.EMPTY_OBJECT_ARRAY;
         }
-        int arguments = args.length;
-        Class<?>[] parameterTypes = new Class[arguments];
-        for (int i = 0; i < arguments; i++) {
-            parameterTypes[i] = args[i].getClass();
-        }
+        Class<?>[] parameterTypes = ClassUtils.toClass(args);
         return invokeExactStaticMethod(cls, methodName, args, parameterTypes);
     }
 

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java?rev=1369102&r1=1369101&r2=1369102&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Fri Aug  3 17:17:18 2012
@@ -371,6 +371,12 @@ public class MethodUtilsTest {
                 singletonArray(ChildObject.class), singletonArray(ChildInterface.class));
     }
 
+    @Test
+    public void testNullArgument() {
+        expectMatchingAccessibleMethodParameterTypes(TestBean.class, "oneParameter",
+                singletonArray(null), singletonArray(String.class));
+    }
+
     private void expectMatchingAccessibleMethodParameterTypes(Class<?> cls,
             String methodName, Class<?>[] requestTypes, Class<?>[] actualTypes)
{
         Method m = MethodUtils.getMatchingAccessibleMethod(cls, methodName,



Mime
View raw message