Skip to content

[COLLECTIONS-891] Fix IndexedCollection contains equality#687

Draft
OldTruckDriver wants to merge 2 commits into
apache:masterfrom
OldTruckDriver:fix/COLLECTIONS-891_indexedcollection_contains_equality
Draft

[COLLECTIONS-891] Fix IndexedCollection contains equality#687
OldTruckDriver wants to merge 2 commits into
apache:masterfrom
OldTruckDriver:fix/COLLECTIONS-891_indexedcollection_contains_equality

Conversation

@OldTruckDriver

Copy link
Copy Markdown
Contributor

[COLLECTIONS-891] Fix IndexedCollection contains equality

IndexedCollection#contains(Object) used the transformed key only, so it could return true for an object that was never added when another object mapped to the same key.

This change keeps the indexed lookup as a fast candidate filter, then checks object equality within the indexed values before returning true.

Tests cover both unique and non-unique indexed collections where "01" and "1" map to the same key but are not equal objects.

Tests run:

  • mvn -q -Dtest=org.apache.commons.collections4.collection.IndexedCollectionTest#testContainsUsesObjectEqualityNotOnlyTransformedKey test
  • mvn -q -Dtest=org.apache.commons.collections4.collection.IndexedCollectionTest#testContainsUsesObjectEqualityWithNonUniqueIndex test
  • mvn -q -Dtest=org.apache.commons.collections4.collection.IndexedCollectionTest test
  • mvn -q

OldTruckDriver and others added 2 commits June 20, 2026 00:21
contains(Object) returned index.containsKey(transform(object)), so it reported true
whenever any element shared the transformed key, breaking Collection.contains for a
non-injective transformer. Look up the key's bucket and check actual object equality
within it. Add tests for unique and non-unique indexes.

Reviewed-by: OpenAI Codex
Reviewed-by: Anthropic Claude Code
@garydgregory garydgregory marked this pull request as draft June 19, 2026 18:03
@garydgregory

Copy link
Copy Markdown
Member

I've converted this PR to a Draft PR until we resolve the discussing in COLLECTIONS-891.

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