RFR 8013649: HashMap spliterator tryAdvance() encounters remaining elements after forEachRemaining()
paul.sandoz at oracle.com
Fri May 31 10:29:02 UTC 2013
Please review a fix to the key/value/entry spliterators of HashMap/WeakHashMap when mixed traversal is performed:
A call to forEachRemaning does not correctly check and set the state to detect/signal all elements have been traversed.
There are two conditions for traversal:
1) if the index into the entry table is less than the fence; or
2) if the current entry is not null.
forEachRemaining was only checking the first condition before traversing and only setting the state associated with the first condition rendering it false on subsequent calls.
If mixed traversal (a combination of tryAdvance and forEachRemaining) is performed this can result in forEachRemaining not traversing elements or tryAdvance traversing previously traversed elements.
Note that failure only occurs for certain distributions of elements which is why the current tests did not detect this case. Additional tests have been added that induce the conditions whereby table entries contain 2 or more elements thus enabling tryAdvance to set up condition 2).
This has already been fixed in the lambda repo:
More information about the core-libs-dev