Avoid infinite recursion in KotlinDetector.hasSerializableAnnotation - #37128
Open
aleksei-averchenko-wise wants to merge 1 commit into
Open
Conversation
Track generic types by identity while traversing nested generics to short-circuit self-referential bounds without relying on recursive ResolvableType equality or hash codes. Closes spring-projectsgh-37127 Signed-off-by: Aleksei Averchenko <aleksei.averchenko@wise.com>
aleksei-averchenko-wise
marked this pull request as ready for review
August 11, 2026 12:19
KotlinDetector.hasSerializableAnnotation
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.
Overview
KotlinDetector.hasSerializableAnnotationrecursively inspects generic types but did not account for self-referential generic bounds. Types such as Guava'sImmutableEnumSet, whose type parameter ultimately refers back to itself, therefore caused aStackOverflowErrorinstead of returning whether Kotlin's@Serializableannotation is present.This change tracks the underlying Java types by identity along the active traversal path. Repeated types short-circuit the current branch without invoking potentially recursive
ResolvableType.equals()orhashCode()implementations, while removing types as the traversal unwinds preserves detection in separate and nested generic branches.AI use disclosure: Assisted by Codex (5.6 Sol Extra High), edited and verified by hand.
Closes #37127.
Changes
KotlinDetector.hasSerializableAnnotation.Testing
./gradlew spring-core:test --tests org.springframework.core.KotlinDetectorTests./gradlew spring-core:checkstyleMain spring-core:checkstyleTest