Author: nbubna
Date: Sat May 23 21:52:50 2009
New Revision: 778038

URL: http://svn.apache.org/viewvc?rev=778038&view=rev
Log:
VELOCITY-718 attempt to prevent infinite HashMap.get() loops

Modified:
    velocity/engine/trunk/src/java/org/apache/velocity/util/MapFactory.java
    
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
    
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/util/MapFactory.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/MapFactory.java?rev=778038&r1=778037&r2=778038&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/util/MapFactory.java 
(original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/util/MapFactory.java Sat 
May 23 21:52:50 2009
@@ -53,7 +53,22 @@
             // not running under JRE 1.5+
         }
     }
-    
+
+    /**
+     * Creates a new instance of a class that implements Map interface
+     * using the JDK defaults for initial size, load factor, etc.
+     * 
+     * Note that there is a small performance penalty because concurrent
+     * maps are created using reflection.
+     * 
+     * @param allowNullKeys if true, the returned Map instance supports null 
keys         
+     * @return one of ConcurrentHashMap, HashMap, Hashtable
+     */
+    public static Map create(boolean allowNullKeys)
+    {
+        return create(16, 0.75f, 16, allowNullKeys);
+    }
+
     /**
      * Creates a new instance of a class that implements Map interface.
      * 

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java?rev=778038&r1=778037&r2=778038&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/ClassMap.java
 Sat May 23 21:52:50 2009
@@ -25,6 +25,7 @@
 import java.util.Map;
 import org.apache.commons.lang.text.StrBuilder;
 import org.apache.velocity.runtime.log.Log;
+import org.apache.velocity.util.MapFactory;
 
 /**
  * A cache of introspection information for a specific class instance.
@@ -215,7 +216,7 @@
          * Cache of Methods, or CACHE_MISS, keyed by method
          * name and actual arguments used to find it.
          */
-        private final Map cache = new HashMap();
+        private final Map cache = MapFactory.create(false);
 
         /** Map of methods that are searchable according to method parameters 
to find a match */
         private final MethodMap methodMap = new MethodMap();

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java?rev=778038&r1=778037&r2=778038&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/util/introspection/MethodMap.java
 Sat May 23 21:52:50 2009
@@ -26,6 +26,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import org.apache.velocity.util.MapFactory;
 
 /**
  *
@@ -45,7 +46,7 @@
     /**
      * Keep track of all methods with the same name.
      */
-    Map methodByNameMap = new HashMap();
+    Map methodByNameMap = MapFactory.create(false);
 
     /**
      * Add a method to a list of methods by name.


Reply via email to