classpath
[Top][All Lists]
Advanced

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

HashMap putAll/putAllInternal bug


From: Stuart Ballard
Subject: HashMap putAll/putAllInternal bug
Date: Wed, 24 Sep 2003 09:47:33 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3.1) Gecko/20030527 Debian/1.3.1-2

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 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 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 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





reply via email to

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