You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Klaasjan Brand <br...@topicus.nl> on 2002/04/03 14:06:58 UTC

[beanutils] methodutils bug + patch

Hi there,

I discovered a bug in the class MethodUtils: when comparing method 
parameters to find a matching method the search is interrupted when 
method parameters don't match, but the non-matching method is still 
returned. When the first method returned by Java is appropriate this bug 
will go unnoticed; it was quite hard to track down...

I fixed it by breaking out of the compare loop and continue with the 
next method candidate as shown in the enclosed patch.

greets,
Klaasjan Brand

Re: [beanutils] methodutils bug + patch

Posted by robert burrell donkin <ro...@mac.com>.
hi Klaasjan

many thanks for your excellent bug report and patch.

i've committed a fix today which is (hopefully) logically equivalent to 
your patch but uses a boolean rather than a label (for stylistic reasons).

i've also corrected another bug in the same passage of code and added new 
tests to cover this area.

would it be possible for you to check that the fix committed works for you?

- robert

On Wednesday, April 3, 2002, at 01:06 PM, Klaasjan Brand wrote:

> Hi there,
>
> I discovered a bug in the class MethodUtils: when comparing method 
> parameters to find a matching method the search is interrupted when 
> method parameters don't match, but the non-matching method is still 
> returned. When the first method returned by Java is appropriate this bug 
> will go unnoticed; it was quite hard to track down...
>
> I fixed it by breaking out of the compare loop and continue with the next 
> method candidate as shown in the enclosed patch.
>
> greets,
> Klaasjan Brand
> --- orig/MethodUtils.java	Wed Apr  3 13:50:22 2002
> +++ fix/MethodUtils.java	Wed Apr  3 13:50:34 2002
> @@ -504,7 +504,7 @@
>          // search through all methods
>          int paramSize = parameterTypes.length;
>          Method[] methods = clazz.getMethods();
> -        for (int i = 0, size = methods.length; i < size ; i++) {
> +        outer: for (int i = 0, size = methods.length; i < size ; i++) {
>              if (methods[i].getName().equals(methodName)) {	
>                  // log some trace information
>                  if (log.isTraceEnabled()) {
> @@ -517,12 +517,12 @@
>                  int methodParamSize = methodsParams.length;
>                  if (methodParamSize == paramSize) {
>                      for (int n = 0 ; n < methodParamSize; n++) {
> -                        if 
> (!parameterTypes[n].isAssignableFrom(methodsParams[n])) {
> +                        if 
> (!methodsParams[n].isAssignableFrom(parameterTypes[n])) {
>                              if (log.isTraceEnabled()) {
>                                  log.trace(parameterTypes[n] + " is not 
> assignable from "
>                                              + methodsParams[n]);
>                              }
> -                            break;
> +                            continue outer;
>                          }
>                      }
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.
> org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.
> org>


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