Avoid Kotlin reflection in MethodParameter for non-suspending functions - #37366
Closed
Asthenia0412 wants to merge 1 commit into
Closed
Asthenia0412 wants to merge 1 commit into
Asthenia0412 wants to merge 1 commit into
Conversation
MethodParameter.getGenericParameterType() and computeParameterType() resolved the return type of any Kotlin method through KotlinDelegate, which calls ReflectJvmMapping.getKotlinFunction(method) solely to check KFunction.isSuspend(). That lookup materializes all members of the declaring KClass and is repeated for every method whose return type is resolved, including the many non-suspending ones. A suspending function always compiles to a JVM method whose last parameter is kotlin.coroutines.Continuation, which KotlinDetector.isSuspendingFunction(Method) already checks without Kotlin reflection. Guard KotlinDelegate.getGenericReturnType(...) and getReturnType(...) with it so that regular Kotlin methods fall back to Java reflection immediately, while suspending functions still go through the KFunction path. Closes spring-projectsgh-37300
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
MethodParameter.getGenericParameterType()andcomputeParameterType()resolve the return type of any Kotlin method throughKotlinDelegate, which callsReflectJvmMapping.getKotlinFunction(method)solely to checkKFunction.isSuspend(). That lookup materializes all members of the declaringKClassand is repeated for every method whose return type is resolved, including the many non-suspending ones.Changes
Guard
KotlinDelegate.getGenericReturnType(...)andgetReturnType(...)withKotlinDetector.isSuspendingFunction(method). A suspending function always compiles to a JVM method whose last parameter iskotlin.coroutines.Continuation, whichisSuspendingFunctionchecks without Kotlin reflection. Suspending functions still go through theKFunctionpath; regular (non-suspending) Kotlin methods now fall back to Java reflection immediately.Related Issue