Skip to content
Commit 093572cd authored by Tobias Thierer's avatar Tobias Thierer
Browse files

Don't allow MapCollections to iterate past the end.

Prior to this CL, MapCollections such as ArrayMap's entrySet,
keySet and values, exhibited unusual Iterator behavior:
 - instead of throwing NoSuchElementException once the end of
   the Collection was reached, Iterator.next() instead returned
   a null key / a null value / an entry with a null key and value.
 - however, remove() removed the last actual element of the
   Collection; successive calls of next(), remove() would
   result in successive elements being removed, in reverse
   iteration order.
 - Once the Collection had been cleared through calls to remove(),
   ArrayIndexOutOfBoundsException was thrown from iterator.next()
   (for keySet and values) or from iterator.remove (for entrySet).

This CL fixes those Collections' Iterators to let next() throw
NoSuchElementException when hasNext() would have returned false.
Since the new behavior was already guaranteed by the Iterator
documentation, any app compatibility effect from this CL is both
unlikely, and unlikely to be negative.

Bug: 19853326
Test: make cts && cts-tradefed run cts -m CtsUtilTestCases
Change-Id: Ie3f0594f434dd5625799791829bd94fbaef94906
parent c7eefdbd
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment