Skip to content

Return unmodifiable collections from getAllKnown* methods - #714

Merged
Ladicek merged 1 commit into
smallrye:mainfrom
basteez:return-unmodifiable-known-collections
Sep 3, 2026
Merged

Ladicek merged 1 commit into
smallrye:mainfrom
basteez:return-unmodifiable-known-collections

Conversation

@basteez

@basteez basteez commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Index and CompositeIndex returned their internal HashSet accumulators directly from getAllKnownSubclasses, getAllKnownSubinterfaces, and getAllKnownImplementors (and, by delegation, getAllKnownImplementations). That let callers mutate the returned set, which was never intended and is inconsistent with the sibling methods such as getKnownDirectSubclasses that already wrap their results with Collections.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 new IndexNavigationTest.testAllKnownCollectionsAreUnmodifiable that checks both Index and CompositeIndex, 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.

@basteez
basteez marked this pull request as ready for review September 2, 2026 16:23
Ladicek
Ladicek previously approved these changes Sep 3, 2026
@Ladicek Ladicek added this to the 3.6.1 milestone 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
Ladicek force-pushed the return-unmodifiable-known-collections branch from ebe00ce to ebffc2f Compare September 3, 2026 07:23
@Ladicek
Ladicek merged commit 044b193 into smallrye:main Sep 3, 2026
85 of 86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants