Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6197726

(coll) IdentityHashMap.entrySet().toArray(T[] a) is incorrectly implemented

XMLWordPrintable

    • b51
    • generic, x86, sparc
    • generic, solaris_9, windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.5.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
        Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        XP SP2

        A DESCRIPTION OF THE PROBLEM :
        (inbound IdentityHashMap ip)

        int sz = ip.size();
        Object [] entries = new Object[sz];
        ip.entrySet().toArray(entries);

        Entries contains nulls, even though there is room for entries in the given array.

        Look at the implementation, we find this:

        public <T> T[] toArray(T[] a) {
        return (T[])toArray(); // !!!!
                }

        Seems like it was never implemented, and a placeholder was left.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        run code above

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        entries array should contain Map.Entry objects, not nulls.

        ACTUAL -
        entries array contains only nulls, as it is never written to.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        IdentityHashMap im = new IdentityHashMap();
        im.put(im,im);
        Object [] o = new Object[1];
        im.entrySet().toArray(o);


        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        never call toArray(object [])

              martin Martin Buchholz
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: