Skip to content

Fix false cycle detection for generic types with different type arguments.#5224

Open
kamilkrzywanski wants to merge 2 commits into
spring-projects:mainfrom
kamilkrzywanski:issue/5213-generic-type-cycle-detection
Open

Fix false cycle detection for generic types with different type arguments.#5224
kamilkrzywanski wants to merge 2 commits into
spring-projects:mainfrom
kamilkrzywanski:issue/5213-generic-type-cycle-detection

Conversation

@kamilkrzywanski

Copy link
Copy Markdown
  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Summary

Fixes a spurious cycle detection in MongoPersistentEntityIndexResolver.CycleGuard.Path when the same generic type appears more than once with different type arguments (for example Selection<FruitBasket> and Selection<String>).

Previously, cycle detection relied on PersistentProperty.equals(), which is based on the reflected field and therefore collapses parameterized owners that share the same raw type. That stopped index resolution early and caused nested @Indexed fields to be ignored, with a misleading Found cycle log message.

Cycle detection now compares the property name together with the owner's resolved TypeInformation, so:

  • distinct type arguments are not treated as a cycle (nested indexes are discovered)
  • genuine recursion through the same parameterized type still stops as before

Related issue

Closes #5213

Test plan

…ents.

CycleGuard.Path used PersistentProperty.equals(), which collapses generic owners that share the same reflected field (for example Selection<FruitBasket> versus Selection<String>). Compare property name and owner TypeInformation instead so nested indexes under distinct type arguments are still resolved.

Closes spring-projects#5213

Signed-off-by: Kamil Krzywanski <kamilkrzywanski01@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 11, 2026
Mock PersistentProperty instances do not share field-based equality, so the previous path unit tests were false-green without the fix. Build the cycle path from MongoMappingContext properties so equals collapses Selection.include across type arguments the same way production does.

Signed-off-by: Kamil Krzywanski <kamilkrzywanski01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MongoPersistentEntityIndexResolver - Found cycle for generic types using different type params

2 participants