During garbage collection, the WeakHashMap will throw a NoSuchElementException when performing the methods: .keySet().toArray() .clear(); and maybe more. Sun's java does not. Here is an example: gcc version 4.0.0 20041014 (experimental) gcj -main=WH WH.java import java.util.*; public class WH { public static void main(String[] s) { Thread t = new Thread() { public void run() { while (true) { System.gc(); try { Thread.sleep(1000); } catch (Exception e) { } } } }; WeakHashMap w = new WeakHashMap(); for (int i = 0; i < 10000; i++) w.put(new WH(), null); t.setDaemon(true); t.start(); try { w.clear(); } catch (NoSuchElementException n) { System.out.println("From .clear(): "); n.printStackTrace(); } for (int i = 0; i < 10000; i++) w.put(new WH(), null); try { for (int i = 0; i < 1000; i++) System.out.print("["+w.keySet().toArray().length+"]"); } catch (NoSuchElementException n) { System.out.println("iFrom .toArray():"); n.printStackTrace(); } } }
*** This bug has been marked as a duplicate of 16998 ***
Lets reopen this one.
*** Bug 16998 has been marked as a duplicate of this bug. ***
Confirmed.
Closing as won't fix as libgcj (and the java front-end) has been removed from the trunk.