commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils MethodUtilsTestCase.java
Date Wed, 04 Sep 2002 19:23:45 GMT
rdonkin     2002/09/04 12:23:45

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        MethodUtils.java
               beanutils/src/test/org/apache/commons/beanutils
                        MethodUtilsTestCase.java
  Log:
  Added enhancement #12247. This makes null parameter arrays pass into invokeXXX methods to
be treated as empty arrays. This improves consistancy with basic reflection.
  
  Revision  Changes    Path
  1.13      +34 -14    jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MethodUtils.java
  
  Index: MethodUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MethodUtils.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MethodUtils.java	15 Aug 2002 20:21:27 -0000	1.12
  +++ MethodUtils.java	4 Sep 2002 19:23:45 -0000	1.13
  @@ -90,12 +90,13 @@
        */
       private static Log log = LogFactory.getLog(MethodUtils.class);
   
  -
  -
  +    /** An empty class array */
  +    private static final Class[] emptyClassArray = new Class[0];
  +    /** An empty object array */
  +    private static final Object[] emptyObjectArray = new Object[0];
  +    
       // --------------------------------------------------------- Public Methods
  -
  -
  -
  +    
       /**
        * <p>Invoke a named method whose parameter type matches the object type.</p>
        *
  @@ -155,7 +156,7 @@
        *
        * @param object invoke method on this object
        * @param methodName get method with this name
  -     * @param args use these arguments
  +     * @param args use these arguments - treat null as empty array
        *
        * @throws NoSuchMethodException if there is no such accessible method
        * @throws InvocationTargetException wraps an exception thrown by the
  @@ -171,7 +172,10 @@
               NoSuchMethodException,
               IllegalAccessException,
               InvocationTargetException {
  -
  +        
  +        if (args == null) {
  +            args = emptyObjectArray;
  +        }  
           int arguments = args.length;
           Class parameterTypes [] = new Class[arguments];
           for (int i = 0; i < arguments; i++) {
  @@ -198,8 +202,8 @@
        *
        * @param object invoke method on this object
        * @param methodName get method with this name
  -     * @param args use these arguments
  -     * @param parameterTypes match these parameters
  +     * @param args use these arguments - treat null as empty array
  +     * @param parameterTypes match these parameters - treat null as empty array
        *
        * @throws NoSuchMethodException if there is no such accessible method
        * @throws InvocationTargetException wraps an exception thrown by the
  @@ -216,7 +220,13 @@
                       NoSuchMethodException,
                       IllegalAccessException,
                       InvocationTargetException {
  -        
  +                    
  +        if (parameterTypes == null) {
  +            parameterTypes = emptyClassArray;
  +        }        
  +        if (args == null) {
  +            args = emptyObjectArray;
  +        }  
   
           Method method = getMatchingAccessibleMethod(
                   object.getClass(),
  @@ -271,7 +281,7 @@
        *
        * @param object invoke method on this object
        * @param methodName get method with this name
  -     * @param args use these arguments
  +     * @param args use these arguments - treat null as empty array
        *
        * @throws NoSuchMethodException if there is no such accessible method
        * @throws InvocationTargetException wraps an exception thrown by the
  @@ -287,7 +297,9 @@
               NoSuchMethodException,
               IllegalAccessException,
               InvocationTargetException {
  -
  +        if (args == null) {
  +            args = emptyObjectArray;
  +        }  
           int arguments = args.length;
           Class parameterTypes [] = new Class[arguments];
           for (int i = 0; i < arguments; i++) {
  @@ -307,8 +319,8 @@
        *
        * @param object invoke method on this object
        * @param methodName get method with this name
  -     * @param args use these arguments
  -     * @param parameterTypes match these parameters
  +     * @param args use these arguments - treat null as empty array
  +     * @param parameterTypes match these parameters - treat null as empty array
        *
        * @throws NoSuchMethodException if there is no such accessible method
        * @throws InvocationTargetException wraps an exception thrown by the
  @@ -325,6 +337,14 @@
               NoSuchMethodException,
               IllegalAccessException,
               InvocationTargetException {
  +        
  +        if (args == null) {
  +            args = emptyObjectArray;
  +        }  
  +                
  +        if (parameterTypes == null) {
  +            parameterTypes = emptyClassArray;
  +        }
   
           Method method = getAccessibleMethod(
                   object.getClass(),
  
  
  
  1.9       +5 -0      jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/MethodUtilsTestCase.java
  
  Index: MethodUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/MethodUtilsTestCase.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MethodUtilsTestCase.java	29 Jul 2002 18:23:45 -0000	1.8
  +++ MethodUtilsTestCase.java	4 Sep 2002 19:23:45 -0000	1.9
  @@ -297,6 +297,11 @@
           } catch (NoSuchMethodException e) {
               // this is what we're expecting!
           }
  +        
  +        MethodUtils.invokeMethod(parent, "getName", null);
  +        MethodUtils.invokeMethod(parent, "getName", null, null);
  +        MethodUtils.invokeExactMethod(parent, "getName", null);
  +        MethodUtils.invokeExactMethod(parent, "getName", null, null);        
       }
   
       
  
  
  

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


Mime
View raw message