[kaffe] HashMap putAll/putAllInternal bug

Stuart Ballard stuart.ballard@corp.fast.net
Wed Sep 24 13:24:02 2003


(sent to classpath, but their mailing list is a blackhole at the moment 
and, being impatient, I figured I'd send to Kaffe where it's also 
relevant, since Kaffe's collections classes come from Classpath)

The HashMap putAll and putAllInternal (called from constructor) methods
use size() to get the size of the map to be added, and then iterate over
the iterator that many times to add elements. Instead, they should call
hasNext() on the iterator.

I can make any number of arguments for why this should be the case, but
if we're arguing on the merits, there are arguments against this change
too, so I won't bother :)

Instead, I'll appeal to "Sun does it this way and we should be
compatible". I've got actual code that breaks on Classpath (and Kaffe) 
due to this difference (I spent *ages* tracking it down, too).

I know that this means my Map classes aren't quite honoring the Map
contract, by not returning the correct value for size(), but I have good
reasons for that - and Sun's implementation doesn't care, so Classpath's 
  (Kaffe's) shouldn't either.

I suspect this problem may be more pervasive - it only bit me on
HashMap, but it may come up on *Map, *Set, and *List, Hashtable and
Vector as well.

If Classpath (or Kaffe) makes this change, I believe I'll be able to 
post the code of my project onto Savannah (they wouldn't accept it until 
it ran on a free Java implementation).

Stuart.

-- 
Stuart Ballard, Senior Web Developer
FASTNET - Web Solutions
(215) 283-2300, ext. 126
www.fast.net