You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2002/04/05 16:58:15 UTC

cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils AbstractParent.java AlphaBean.java MethodUtilsTestCase.java

rdonkin     02/04/05 06:58:15

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        MethodUtils.java
               beanutils/src/test/org/apache/commons/beanutils
                        AbstractParent.java AlphaBean.java
                        MethodUtilsTestCase.java
  Log:
  Fixed bug 7740. Klaasjan Brand supplied a patch which was very helpful in locating the problem but a slightly different patch was committed mainly for stylistic reasons. Also added extra tests covering the cause of failure. Also corrected another coding mistake (again mea culpa) in the same passage of code.
  
  Revision  Changes    Path
  1.9       +21 -13    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MethodUtils.java	24 Mar 2002 09:15:16 -0000	1.8
  +++ MethodUtils.java	5 Apr 2002 14:58:15 -0000	1.9
  @@ -515,28 +515,36 @@
                   // compare parameters
                   Class[] methodsParams = methods[i].getParameterTypes();
                   int methodParamSize = methodsParams.length;
  -                if (methodParamSize == paramSize) {                    
  +                if (methodParamSize == paramSize) {          
  +                    boolean match = true;
                       for (int n = 0 ; n < methodParamSize; n++) {
  -                        if (!parameterTypes[n].isAssignableFrom(methodsParams[n])) {
  +                        if (log.isTraceEnabled()) {
  +                            log.trace("Param=" + parameterTypes[n].getName());
  +                            log.trace("Method=" + methodsParams[n].getName());
  +                        }
  +                        if (!methodsParams[n].isAssignableFrom(parameterTypes[n])) {
                               if (log.isTraceEnabled()) {
  -                                log.trace(parameterTypes[n] + " is not assignable from " 
  -                                            + methodsParams[n]);
  +                                log.trace(methodsParams[n] + " is not assignable from " 
  +                                            + parameterTypes[n]);
                               }    
  +                            match = false;
                               break;
                           }
                       }
                       
  -                    // get accessible version of method
  -                    Method method = getAccessibleMethod(methods[i]);
  -                    if (method != null) {
  -                        if (log.isTraceEnabled()) {
  -                            log.trace(method + " accessible version of " 
  -                                        + methods[i]);
  +                    if (match) {
  +                        // get accessible version of method
  +                        Method method = getAccessibleMethod(methods[i]);
  +                        if (method != null) {
  +                            if (log.isTraceEnabled()) {
  +                                log.trace(method + " accessible version of " 
  +                                            + methods[i]);
  +                            }
  +                            return method;
                           }
  -                        return method;
  +                        
  +                        log.trace("Couldn't find accessible method.");
                       }
  -                    
  -                    log.trace("Couldn't find accessible method.");
                   }
               }
           }
  
  
  
  1.2       +15 -0     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/AbstractParent.java
  
  Index: AbstractParent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/AbstractParent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractParent.java	6 Mar 2002 20:21:24 -0000	1.1
  +++ AbstractParent.java	5 Apr 2002 14:58:15 -0000	1.2
  @@ -66,6 +66,20 @@
           return child;
       }
   
  +    /**
  +     * Method which matches signature but which has wrong parameters 
  +     */
  +    public String testAddChild(String badParameter) {
  +        return null;
  +    }
  +
  +    /**
  +     * Method which matches signature but which has wrong parameters 
  +     */
  +    public String testAddChild2(String ignore, String badParameter) {
  +        return null;
  +    }
  +    
       public String testAddChild(Child child) {
           this.child = child;
           return child.getName();
  @@ -76,4 +90,5 @@
           this.child = child;
           return child.getName();
       }
  +
   }
  
  
  
  1.2       +6 -1      jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/AlphaBean.java
  
  Index: AlphaBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/AlphaBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AlphaBean.java	6 Mar 2002 20:21:24 -0000	1.1
  +++ AlphaBean.java	5 Apr 2002 14:58:15 -0000	1.2
  @@ -67,5 +67,10 @@
       
       public String getName() {
           return name;
  -    }
  +    }    
  +    
  +    /**
  +     * Used for testing that correct exception is thrown.
  +     */
  +    public void bogus(String badParameter){}
   }
  
  
  
  1.6       +12 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MethodUtilsTestCase.java	6 Mar 2002 20:21:24 -0000	1.5
  +++ MethodUtilsTestCase.java	5 Apr 2002 14:58:15 -0000	1.6
  @@ -285,5 +285,17 @@
                           "ChildTwo", 
                           MethodUtils.invokeMethod(parent, "testAddChild2", params));
           
  +        // test that exception is correctly thrown when a method cannot be found with matching params
  +        try {
  +            // the next line
  +            parent = new AlphaBean("parent");
  +            childOne = new BetaBean("ChildOne");
  +            MethodUtils.invokeMethod(parent, "bogus", childOne);
  +            // should get here!
  +            fail("No exception thrown when no appropriate method exists");
  +            
  +        } catch (NoSuchMethodException e) {
  +            // this is what we're expecting!
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>