Skip to content

Conversation

@nickita-khylkouski
Copy link

Fixes #8165

Summary

  • CollectSpliterators.filter(): Preserve IMMUTABLE and CONCURRENT characteristics from the source spliterator. These describe the source, not the elements, so filtering does not invalidate them. This aligns with JDK Stream.filter(), which only clears SIZED.

  • Lists inner classes: Add spliterator() overrides to OnePlusArrayList, TwoPlusArrayList, CharSequenceAsList, and AbstractListWrapper so they report accurate characteristics (ORDERED, SIZED, IMMUTABLE where applicable) instead of falling back to AbstractList defaults.

  • Maps inner classes: Add spliterator() overrides to KeySet (propagates DISTINCT via CollectSpliterators.map()) and Values (propagates source characteristics via CollectSpliterators.map()).

Test plan

  • Added testFilterPreservesImmutableCharacteristic and testFilterDropsSized to CollectSpliteratorsTest
  • Added testAsListSpliteratorIsImmutable, testAsListTwoSpliteratorIsImmutable, testCharactersOfSpliteratorCharacteristics, and testAbstractListWrapperSpliteratorDelegates to ListsTest
  • Added testKeySetSpliteratorIsDistinct and testValuesSpliteratorPreservesCharacteristics to MapsTest
  • All new tests pass locally
  • Regression tests (Collections2Test, SetsTest) pass locally

Fix CollectSpliterators.filter() to preserve IMMUTABLE and CONCURRENT
characteristics from the source spliterator, matching JDK Stream.filter()
behavior which only clears SIZED.

Add spliterator() overrides to Lists inner classes (OnePlusArrayList,
TwoPlusArrayList, CharSequenceAsList, AbstractListWrapper) and Maps
inner classes (KeySet, Values) so that collection views properly report
their characteristics rather than falling back to AbstractList defaults.

Fixes google#8165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 no SLO

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lists::transform and probably others do not produce spliterators/iterators with correct characteristics

2 participants