From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 838 invoked by alias); 12 Aug 2004 02:26:45 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 821 invoked by uid 48); 12 Aug 2004 02:26:45 -0000 Date: Thu, 12 Aug 2004 02:26:00 -0000 From: "mckinlay at redhat dot com" To: java-prs@gcc.gnu.org Message-ID: <20040812022643.16998.mckinlay@redhat.com> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libgcj/16998] New: WeakHashMap iterator can throw NoSuchElementException unexpectedly X-Bugzilla-Reason: CC X-SW-Source: 2004-q3/txt/msg00220.txt.bz2 List-Id: 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