classpath
[Top][All Lists]
Advanced

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

Re: Hashtable enumeration


From: Patrick Doyle
Subject: Re: Hashtable enumeration
Date: Thu, 6 Sep 2001 12:36:41 -0400 (EDT)

On Thu, 6 Sep 2001, Bryce McKinlay wrote:

> This is not a bug in classpath's Hashtable implementation. The behaviour 
> here is undefined, and it is very dangerous to add elements to a 
> Hashtable while an enumeration is in progress. For example if a rehash 
> occurs, the table will be reordered and elements which have already been 
> enumerated could be returned again.

The choice of which elements will be enumerated may be undefined, but
Classpath's implementation is still wrong.  The spec for
Enumeration.hasMoreElements says this:

  Returns:
    true if and only if this enumeration object contains at least one more
    element to provide; false otherwise.

So, it seems clear to me that if hasMoreElements returns true, then
nextElement should not throw a NoSuchElementException.  It can return
whatever element it wants, but it can't throw that exception.

> Patrick, can you try this in your tree against the 213_javac. If it
> solves the problem you are seeing, I'll check it in.

They won't send me their source code, and they won't tell me which patches
are the ones to use.  After an initial email where they declined to tell
me anything, I haven't heard from them since.

So, I implemented it a really dumb way:

   public boolean hasMoreElements()
    {
      /* I don't care if it's efficient; it just has to work */
      try{
        ((HashtableEnumeration)this.clone()).nextElement();
        /* No exception; there must be another element */
        return true;
      }catch(NoSuchElementException e){
        return false;
      }catch(CloneNotSupportedException e){
        throw new InternalError();
      }
    }

Clearly this is about as inefficient as it could be, but it allows me to
run the javac benchmark.  That's good enough for my purposes, so I haven't
taken the time to re-engineer the enumeration process, especially since
someone else has apparently already done it.

I'll gladly try running the benchmark using any Hashtable.java someone
cares to provide.

--
Patrick Doyle
address@hidden




reply via email to

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