public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/16998] New: WeakHashMap iterator can throw NoSuchElementException unexpectedly
@ 2004-08-12 2:26 mckinlay at redhat dot com
2004-10-27 19:46 ` [Bug libgcj/16998] " pinskia at gcc dot gnu dot org
2004-10-28 14:26 ` pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: mckinlay at redhat dot com @ 2004-08-12 2:26 UTC (permalink / raw)
To: java-prs
The following test case demonstrates that WeakHashMap's iterator().next() can
throw NoSuchElementException even if hasNext() returned true. This probably
should not be possible - although WeakHashMap is a special case by the spec,
iterator behaviour is not one of those cases.
It seems reasonable to expect that if hasNext() returns true, next() will not fail.
Possible solution: have hasNext() grab a reference to the element which will be
returned by the subsequent next() call.
import java.util.WeakHashMap;
public class WH {
public static void main(String[] s) {
WeakHashMap w = new WeakHashMap();
for (int i = 0; i < 100000; i++)
w.put(new WH(), null);
for (int i = 0; i < 1000; i++)
System.out.println(w.keySet().toArray().length);
}
}
--
Summary: WeakHashMap iterator can throw NoSuchElementException
unexpectedly
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libgcj
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mckinlay at redhat dot com
CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16998
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-10-28 14:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-12 2:26 [Bug libgcj/16998] New: WeakHashMap iterator can throw NoSuchElementException unexpectedly mckinlay at redhat dot com
2004-10-27 19:46 ` [Bug libgcj/16998] " pinskia at gcc dot gnu dot org
2004-10-28 14:26 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).