Bug 18187 - java.util.WeakHashMap$WeakEntrySet.next() throws NoSuchElementException during GC
Summary: java.util.WeakHashMap$WeakEntrySet.next() throws NoSuchElementException durin...
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 16998 (view as bug list)
Depends on:
Blocks: 27598
  Show dependency treegraph
 
Reported: 2004-10-27 19:44 UTC by Rutger Ovidius
Modified: 2016-09-30 22:54 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-28 14:26:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rutger Ovidius 2004-10-27 19:44:32 UTC
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();
    }

  }

}
Comment 1 Andrew Pinski 2004-10-27 19:46:53 UTC

*** This bug has been marked as a duplicate of 16998 ***
Comment 2 Andrew Pinski 2004-10-28 14:25:41 UTC
Lets reopen this one.
Comment 3 Andrew Pinski 2004-10-28 14:26:03 UTC
*** Bug 16998 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-10-28 14:26:39 UTC
Confirmed.
Comment 5 Andrew Pinski 2016-09-30 22:54:13 UTC
Closing as won't fix as libgcj (and the java front-end) has been removed from the trunk.