|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
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 [])
|