classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix for Hashtable contains blowing up the stack


From: Dalibor Topic
Subject: Re: [PATCH] Fix for Hashtable contains blowing up the stack
Date: Fri, 21 Nov 2003 20:48:17 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312

Dalibor Topic wrote:
Hi all,

attached is my fix to make ant (I think) work again with Classpath, fixing the bug reported by Jim Pick here [1]

Citing myself [2]:
this is a typical java library bug, and I've both produced and fixed a couple of those myself ;) You get an infinite recursion through calling overridden methods. Class A in library implements public methods b and c, where b internally (and of course undocumentedly ;) calls c. Class B from some user of the library extends A and overrides c to call b. When the user calls the method b of class B it goes straight into an infinite loop.

The fix is to avoid calling overridable methods from overridable methods, and to delegate those calls to internal, non-overridable versions of the methods.

2003-11-21  Dalibor Topic <address@hidden>

        * libraries/javalib/java/util/Hashtable.java:
        (internalcontainsValue) new method.
        (contains, containsValue) delegate to internalContainsValue.

        Reported by: Jim Pick <address@hidden>

cheers,
dalibor topic

[1] http://mail.gnu.org/archive/html/classpath/2003-09/msg00009.html
[2] http://mail.gnu.org/archive/html/classpath/2003-09/msg00016.html

And this time, I even attached the patch! ;)

cheers,
dalbor topic
--- /var/tmp/PROJECTS/classpath//./java/util/Hashtable.java     Wed Nov 12 
21:56:20 2003
+++ /tmp/topic/kaffe/libraries/javalib/java/util/Hashtable.java Fri Oct 10 
18:49:09 2003
@@ -333,7 +333,10 @@
    */
   public synchronized boolean contains(Object value)
   {
-    return containsValue(value);
+    /* delegate to non-overridable worker method 
+     * to avoid blowing up the stack.
+     */
+    return internalContainsValue(value);
   }
 
   /**
@@ -349,6 +352,25 @@
    * @since 1.2
    */
   public boolean containsValue(Object value)
+  {
+    /* delegate to non-overridable worker method 
+     * to avoid blowing up the stack.
+     */
+    return internalContainsValue(value);
+  }
+
+  /**
+   * Returns true if this Hashtable contains a value <code>o</code>, such that
+   * <code>o.equals(value)</code>. This is an internal worker method
+   * called by <code>contains()</code> and <code>containsValue()</code>.
+   *
+   * @param value the value to search for in this Hashtable
+   * @return true if at least one key maps to the value
+   * @see #contains(Object)
+   * @see #containsKey(Object)
+   * @throws NullPointerException if <code>value</code> is null
+   */
+  private boolean internalContainsValue(Object value)
   {
     for (int i = buckets.length - 1; i >= 0; i--)
       {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]