Repository navigation
[COLLECTIONS-732] Document that MultiValuedMap.mapIterator() does not support setValue() - #748
Open
sharanggupta wants to merge 1 commit into
Conversation
… support setValue() The iterator returned by mapIterator() iterates read-only MultiValuedMapEntry instances, so MapIterator.setValue(Object) always throws UnsupportedOperationException, but neither the interface nor the implementation said so. Say it in the Javadoc of MultiValuedMap.mapIterator(), of the AbstractMultiValuedMap override and of the iterator's setValue(), and point to remove() plus put() as the way to replace a value. No code change; the behaviour is already pinned by AbstractMultiValuedMapTest.testMapIteratorUnsupportedSet().
kinow
reviewed
Oct 14, 2026
kinow
left a comment
Member
There was a problem hiding this comment.
I've allowed GH Actions to run. I haven't looked at the API lately, so I can do a review but it will take a few days until I have time to sync the code and read it. @garydgregory feel free to review it before if you'd like 👍
Thanks for the PR @sharanggupta !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes COLLECTIONS-732.
What
MultiValuedMap.mapIterator()returns an iterator whosesetValue(Object)always throwsUnsupportedOperationException(theMultiValuedMapEntryinstances it iterates are read-only), but neither the interface Javadoc nor the implementation said so, which is what the ticket asked for; @kinow invited a Javadoc PR there in 2020.How
Javadoc only, no code change:
MultiValuedMap#mapIterator(): says that the iterator visits one key-value mapping at a time, that the implementations in this library do not supportMapIterator#setValue(Object)and throwUnsupportedOperationExceptionfrom it, and how to replace a value instead (remove()/removeMapping+put).AbstractMultiValuedMap#mapIterator():{@inheritDoc}plus the same note for this implementation.AbstractMultiValuedMap.MultiValuedMapIterator#setValue(Object): documents theIllegalStateExceptionbeforenext()and theUnsupportedOperationExceptionotherwise.The behaviour itself is already pinned by
AbstractMultiValuedMapTest.testMapIteratorUnsupportedSet, so no test was added. Verified locally with the defaultmvngoal on Java 17 (full test suite: 22,257 tests, plus RAT, Javadoc, japicmp, Checkstyle and PMD).Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.