You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2006/09/29 06:59:54 UTC

svn commit: r451120 - /jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java

Author: wglass
Date: Thu Sep 28 21:59:53 2006
New Revision: 451120

URL: http://svn.apache.org/viewvc?view=rev&rev=451120
Log:
tweaked inner class of method cache.  Related to VELOCITY-453.

Modified:
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java

Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?view=diff&rev=451120&r1=451119&r2=451120
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java (original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java Thu Sep 28 21:59:53 2006
@@ -19,6 +19,7 @@
 import java.lang.reflect.InvocationTargetException;
 
 import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.velocity.app.event.EventHandlerUtil;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
@@ -326,8 +327,12 @@
 
         public MethodCacheKey(String methodName, Class[] params)
         {
-            this.methodName = methodName;
-            this.params = params;
+            /** 
+             * Should never be initialized with nulls, but to be safe we refuse 
+             * to accept them.
+             */
+            this.methodName = (methodName != null) ? methodName : StringUtils.EMPTY;
+            this.params = (params != null) ? params : ArrayUtils.EMPTY_CLASS_ARRAY;
         }
 
         /**
@@ -336,22 +341,13 @@
         public boolean equals(Object o)
         {
             /** 
-             * null check is not strictly needed (due to sole 
-             * initialization above) but it seems more safe
-             * to include it.
-             */
+             * note we skip the null test for methodName and params
+             * due to the earlier test in the constructor
+             */            
             if (o instanceof MethodCacheKey) 
             {
-                final MethodCacheKey other = (MethodCacheKey) o;
-                if ((params == null) || (other.params == null))
-                {
-                    return params == other.params;
-                }             
-                
-                /**
-                 * similarly, do null check on each array subscript.
-                 */
-                else if (params.length == other.params.length && 
+                final MethodCacheKey other = (MethodCacheKey) o;                
+                if (params.length == other.params.length && 
                         methodName.equals(other.methodName)) 
                 {              
                     for (int i = 0; i < params.length; ++i) 
@@ -383,15 +379,9 @@
             int result = 17;
 
             /** 
-             * null check is not strictly needed (due to sole 
-             * initialization above) but it seems more safe to 
-             * include it.
-             */
-            if (params == null)
-            {
-                return result;
-            }
-            
+             * note we skip the null test for methodName and params
+             * due to the earlier test in the constructor
+             */            
             for (int i = 0; i < params.length; ++i)
             {
                 final Class param = params[i];
@@ -401,11 +391,8 @@
                 }
             }
             
-            if (methodName != null)
-            {
-                result = result * 37 + methodName.hashCode();
-            }
-            
+            result = result * 37 + methodName.hashCode();
+
             return result;
         } 
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org