geirm       2002/07/24 18:35:04

  Modified:    src/java/org/apache/velocity/util/introspection Tag:
                        VEL_1_3_BRANCH MethodMap.java
  Log:
  fix for when passing nulls as args
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.13.2.3  +31 -11    
jakarta-velocity/src/java/org/apache/velocity/util/introspection/MethodMap.java
  
  Index: MethodMap.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/util/introspection/MethodMap.java,v
  retrieving revision 1.13.2.2
  retrieving revision 1.13.2.3
  diff -u -r1.13.2.2 -r1.13.2.3
  --- MethodMap.java    24 Jul 2002 22:03:48 -0000      1.13.2.2
  +++ MethodMap.java    25 Jul 2002 01:35:04 -0000      1.13.2.3
  @@ -71,6 +71,8 @@
    */
   public class MethodMap
   {
  +    protected static final Object OBJECT = new Object();
  +
       /**
        * Keep track of all methods with the same name.
        */
  @@ -237,7 +239,7 @@
        */
       private Twonk calcDistance(Object[] set, Class[] base)
       {
  -        if ( set.length != base.length)
  +        if (set.length != base.length)
               return null;
               
           Twonk twonk = new Twonk(set.length);
  @@ -249,16 +251,34 @@
               /* 
                * can I get from here to there?
                */
  -             
  -            Class setclass = set[i].getClass();
  -             
  -            if (!base[i].isAssignableFrom(setclass))
  +
  +            Object invocationArg = set[i];
  +            Class methodClass = base[i];
  +
  +            if (invocationArg == null)
  +            {
  +                invocationArg = OBJECT;
  +            }
  +
  +            Class setclass = invocationArg.getClass();
  +
  +            if (!methodClass.isAssignableFrom(setclass))
               {
                   /*
  -                 * check to see if we are dealing with primitives
  +                 * if the arg is null and methodClass isn't primitive then
  +                 *  that's ok
                    */
  -                if (checkPrimitive(base[i], setclass))
  +
  +                if (set[i] == null && !methodClass.isPrimitive())
  +                {
  +                    continue;
  +                }
  +                else if (checkPrimitive(methodClass, setclass))
                   {
  +                    /*
  +                     * if we are dealing with primitives and it's ok...
  +                     */
  +
                       continue;
                   }
                   else
  @@ -273,13 +293,13 @@
              
               Class c = setclass;
                         
  -            while( c != null)
  +            while (c != null)
               {      
                   /*
                    * is this a valid step?
                    */
                    
  -                if (!base[i].isAssignableFrom(c))
  +                if (!methodClass.isAssignableFrom(c))
                   {      
                       /*
                        *  it stopped being assignable - therefore we are looking at
  @@ -289,7 +309,7 @@
                       break;
                   }
                   
  -                if (base[i].equals(c))
  +                if (methodClass.equals(c))
                   {
                       /*
                        *  we are equal, so no need to move forward
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to