Skip to content

Deduplicate CompositeIndex results by class name (#174) - #707

Closed
basteez wants to merge 1 commit into
smallrye:mainfrom
basteez:issue-174-remove-set-classinfo
Closed

basteez wants to merge 1 commit into
smallrye:mainfrom
basteez:issue-174-remove-set-classinfo

Conversation

@basteez

@basteez basteez commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #174.

Problem

ClassInfo defines no equals/hashCode, so the HashSet<ClassInfo> accumulators in Index and CompositeIndex deduplicate by object identity. In an overlapping CompositeIndex (the same class indexed in more than one member index) this let the same fully-qualified class name appear once per index in the results of:

  • getKnownDirectSubclasses / getAllKnownSubclasses
  • getKnownDirectSubinterfaces / getAllKnownSubinterfaces
  • getKnownDirectImplementations
  • getKnownDirectImplementors / getAllKnownImplementors

This was inconsistent with getKnownUsers, getClassesInPackage, and getAllKnownSubinterfaces' worklist, which already deduplicate by clazz.name().

Change

Replaced the internal Set<ClassInfo> accumulators/parameters/locals in Index and CompositeIndex with name-keyed Map<DotName, ClassInfo> (LinkedHashMap for deterministic order; putIfAbsent/containsKey = first-writer-wins, matching getClassByName, which returns the first index's match). The traversal/visited-tracking logic (processedClasses, worklists) is unchanged.

  • Public API is preserved. Declared return types are identical — the methods declared Set<ClassInfo> still return a Set (materialized from the deduplicated map values at the boundary); Collection<ClassInfo> returners still return a Collection. No IndexView signature, no equals/hashCode on ClassInfo, no on-disk index-format change. Indexer is untouched.
  • Base source set stays Java 8 compatible.

Behavior changes (please review)

  1. Deduplication by name for the methods above on an overlapping CompositeIndex. This is the substance of Get rid of Set<ClassInfo> usages #174. Since @Ladicek noted he wasn't fully convinced the identity semantics were safe to drop, I've kept this deliberate and easy to review: IndexNavigationTest.testOverlappingCompositeIndex previously asserted the duplicate-preserving behavior and is updated here to assert the deduplicated results. Happy to adjust the direction based on your preference.
  2. A few getAll* methods that previously returned a mutable set now return an unmodifiable collection, consistent with the sibling getKnownDirect* methods that already did.

Tests

  • Added CompositeTestCase.testCompositeDeduplicatesByClassName: two indexes each contributing a distinct ClassInfo instance for the same FQCN; asserts the composite returns exactly one entry per name across the affected accessors.
  • Updated IndexNavigationTest.testOverlappingCompositeIndex to expect deduplicated-by-name results.
  • Full core build is green (302 tests) on JDK 21, formatter + impsort clean.

ClassInfo defines no equals/hashCode, so the HashSet<ClassInfo>
accumulators in Index and CompositeIndex deduplicated by identity. In an
overlapping CompositeIndex this let the same fully-qualified class name
appear once per index in the known-subclasses/-subinterfaces/-implementors
results, inconsistent with getKnownUsers/getClassesInPackage which already
deduplicate by name.

Replace those internal accumulators with name-keyed Map<DotName, ClassInfo>
(LinkedHashMap, first-writer-wins to match getClassByName). Public return
types are unchanged; results are now deduplicated by class name and returned
as unmodifiable collections.

testOverlappingCompositeIndex is updated to expect deduplicated results and
a focused regression test is added to CompositeTestCase.

Signed-off-by: Tiziano Basile <[email protected]>
@Ladicek

Ladicek commented Aug 24, 2026

Copy link
Copy Markdown
Member

Handling of duplicate classes is not documented at all in CompositeIndex, so technically anything goes, but changing it feels like huge behavioral breakage. But the changes here that ensure unmodifiable collections are returned are good, I'd accept those.

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.

Get rid of Set<ClassInfo> usages

2 participants