Repository navigation
track wrapped iterator removability in ListIteratorWrapper - #746
Open
rootvector2 wants to merge 1 commit into
Open
rootvector2 wants to merge 1 commit into
rootvector2 wants to merge 1 commit into
Conversation
next() set removeState only when it pulled a fresh element from the wrapped iterator and previous() derived it from the cursor position alone, so remove() rejected a legal removal after reading back out of the element cache, and reset() left the flag set so remove() deleted an element it had to reject.
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.
ListIteratorWrapper.remove()gates on aremoveStateflag thatnext()sets only in the branch that pulls a fresh element from the wrapped iterator, andprevious()recomputes it from the cursor position alone, so walking back into the element cache withprevious()and then forward again until the cursor is level with the wrapped iterator leaves the flag false andremove()throwsIllegalStateExceptionfor a removaljava.util.ListIteratorrequires to succeed, whilereset()rewinds the cursor without clearing the flag sonext(),reset(),remove()deletes an element theremove()javadoc says it must reject; the flag is now derived from whether the element last returned by the wrapped iterator can still be removed from it. Found with a randomized differential test of the library's list iterators againstjava.util.ArrayList.listIterator(), which also confirmedListIteratorWrapperis the only one that caches a plainIteratorthis way (the siblings either delegate to a realListIteratoror rejectremove()outright).mvn; that'smvnon the command line by itself.