Skip to content

check the predicate on entries from filterEntries entrySet().toArray() - #8758

Open
arshsmith1 wants to merge 1 commit into
google:masterfrom
arshsmith1:filtered-entryset-toarray
Open

arshsmith1 wants to merge 1 commit into
google:masterfrom
arshsmith1:filtered-entryset-toarray

Conversation

@arshsmith1

Copy link
Copy Markdown
Contributor

Maps.filterValues and Maps.filterEntries document that Entry.setValue throws IllegalArgumentException for a value the predicate rejects, but FilteredEntryMap.EntrySet only wraps the entries handed out by iterator(). entrySet().toArray() and toArray(T[]) forward to the underlying filtered set and return the backing map's own entries, so ((Entry<String, Integer>) view.entrySet().toArray()[0]).setValue(-1) writes a rejected value through a view that refuses the same write via put, the iterator, replaceAll, merge and compute. Overriding both toArray methods with standardToArray() is the same guard AbstractBiMap.EntrySet and Maps.UnmodifiableEntries already use against the CheckedEntrySet attack; the new test in AbstractFilteredMapTest fails before the change for the Map, SortedMap and BiMap variants and passes after.

FilteredEntryMap.EntrySet wrapped only the entries returned by
iterator(), so the entries returned by toArray() were the backing
map's own entries and their setValue bypassed the filter. Override
toArray the same way AbstractBiMap.EntrySet and UnmodifiableEntries do.
@cpovirk cpovirk self-assigned this Oct 19, 2026
@cpovirk cpovirk added type=defect Bug, not working as expected package=collect P2 labels Oct 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 package=collect type=defect Bug, not working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants