-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
None
-
beta2
-
x86
-
windows_2000
The implementation of AbstractCollection.toArray () is as follows:
public Object[] toArray (Object a[]) {
int size = size ();
...
Iterator it = iterator ();
for (int i=0; i < size; i++)
a [i] = it.next ();
...
}
In case of WeakHashMap.keySet () (it is a collection), a situation when GC clears some weak keys after the size is obtained can occure (even if we synchronize on the WeakHashMap). It implies that java.util.NoSuchElementException is thrown, because the 'for' cycle expects 'size' elements in the iterator 'it'.
public Object[] toArray (Object a[]) {
int size = size ();
...
Iterator it = iterator ();
for (int i=0; i < size; i++)
a [i] = it.next ();
...
}
In case of WeakHashMap.keySet () (it is a collection), a situation when GC clears some weak keys after the size is obtained can occure (even if we synchronize on the WeakHashMap). It implies that java.util.NoSuchElementException is thrown, because the 'for' cycle expects 'size' elements in the iterator 'it'.