Fix false cycle detection for generic types with different type arguments.#5224
Open
kamilkrzywanski wants to merge 2 commits into
Open
Conversation
…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>
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>
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.
Summary
Fixes a spurious cycle detection in
MongoPersistentEntityIndexResolver.CycleGuard.Pathwhen the same generic type appears more than once with different type arguments (for exampleSelection<FruitBasket>andSelection<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@Indexedfields to be ignored, with a misleadingFound cyclelog message.Cycle detection now compares the property name together with the owner's resolved
TypeInformation, so:Related issue
Closes #5213
Test plan
PathUnitTestsfor same property name on generic owners with different / same type argumentsMongoPersistentEntityIndexResolverUnitTestscovering the MongoPersistentEntityIndexResolver - Found cycle for generic types using different type params #5213 repro (FruitShop) and a genuine generic cycle (GenericTreeDocument)./mvnw -pl spring-data-mongodb -Dtest=PathUnitTests,MongoPersistentEntityIndexResolverUnitTests test— 101 tests, 0 failures