On second thought, review of the JDK Hashtable source code points out
that my suggested fix modifies the behavior of Hashtable's keySet()
method.  Hashtable's implementation manages to return a sychronized
reference to its Set of keys via some java.util.Collections
machinations.  The proper fix here is to simply remove
SequencedHashtable's values() method over-ride, and to add yourself to
the author's list.  ;)

Dan


Daniel Rall <[EMAIL PROTECTED]> writes:

> Hi Henning, you're quite right that this is a bug--thanks for the
> detailed description and sample code.  :)
> 
> The existing values() method should be removed (an implementation of
> it already exists in Hashtable), and a cheaper method which is in line
> with the existing java.util.Map interface:
> 
> public Set keySet()
> {
>     return new HashSet(keySequence);
> }
> 
> You'll need to import HashSet.
> 
> 
> "Henning P. Schmiedehausen" <[EMAIL PROTECTED]> writes:
> 
> > Index: SequencedHashtable.java
> > ===================================================================
> > RCS file: 
>/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/util/SequencedHashtable.java,v
> > retrieving revision 1.4
> > diff -u -r1.4 SequencedHashtable.java
> > --- SequencedHashtable.java 2001/05/20 02:38:52     1.4
> > +++ SequencedHashtable.java 2001/06/01 14:18:09
> > @@ -57,6 +57,7 @@
> >  import java.util.Collection;
> >  import java.util.Hashtable;
> >  import java.util.Iterator;
> > +import java.util.List;
> >  import java.util.LinkedList;
> >  import java.util.Map;
> >  import java.util.Set;
> > @@ -73,6 +74,7 @@
> >   * the use of a list of <code>Map.Entry</code> objects.
> >   *
> >   * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
> > + * @author <a href="mailto:[EMAIL PROTECTED]";>Henning P. Schmiedehausen</a>
> >   * @version $Id: SequencedHashtable.java,v 1.4 2001/05/20 02:38:52 dlr Exp $
> >   */
> >  public class SequencedHashtable extends Hashtable
> > @@ -261,10 +263,14 @@
> >      }
> >  
> >      /**
> > -     * Slightly cheaper implementation of <code>values()</code> method.
> > +     * Returns the keys in the table as a List.
> > +     *
> > +     * @return    List of all keys
> >       */
> > -    public Collection values ()
> > +  
> > +    public List keyList()
> >      {
> >          return keySequence;
> >      }
> > +
> >  }

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

Reply via email to