Repository navigation
Return unmodifiable collections from getAllKnown* methods - #714
Merged
Ladicek merged 1 commit intoSep 3, 2026
Merged
Conversation
basteez
marked this pull request as ready for review
September 2, 2026 16:23
Ladicek
previously approved these changes
Sep 3, 2026
`Index` and `CompositeIndex` returned their internal `HashSet` accumulators directly from `getAllKnownSubclasses`, `getAllKnownSubinterfaces` and `getAllKnownImplementors` (and, by delegation, `getAllKnownImplementations`). Callers could mutate those sets, which is neither intended nor consistent with the sibling methods such as `getKnownDirectSubclasses` that already wrap their results with `Collections.unmodifiableSet`. Wrap the returned sets so all of these methods hand back an unmodifiable view. Contents and element order are unchanged; only mutation now fails with `UnsupportedOperationException`. Signed-off-by: Tiziano Basile <[email protected]>
Ladicek
force-pushed
the
return-unmodifiable-known-collections
branch
from
September 3, 2026 07:23
ebe00ce to
ebffc2f
Compare
Ladicek
approved these changes
Sep 3, 2026
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.
IndexandCompositeIndexreturned their internalHashSetaccumulators directly fromgetAllKnownSubclasses,getAllKnownSubinterfaces, andgetAllKnownImplementors(and, by delegation,getAllKnownImplementations). That let callers mutate the returned set, which was never intended and is inconsistent with the sibling methods such asgetKnownDirectSubclassesthat already wrap their results withCollections.unmodifiableSet.This wraps the returned sets so all of these methods hand back an unmodifiable view. Contents and iteration order are unchanged; the only new behavior is that mutating the result now fails with
UnsupportedOperationException.This is the part of #707 you said was acceptable, split out on its own without the name-based deduplication from that PR.
Verified with
mvn -pl core test(317 tests, all passing), including a newIndexNavigationTest.testAllKnownCollectionsAreUnmodifiablethat checks bothIndexandCompositeIndex, before and after a serialization roundtrip.One thing worth calling out: this is a behavioral tightening, so any existing code that mutates a returned set would now break with
UnsupportedOperationException.