spring-projects / spring-projects/spring-framework
KotlinReflectionParameterNameDiscoverer doesn't support Kotlin Context Parameters
Open
@sdeleuze is already working on this.
Since Jun 30, 2025.
in: core
status: feedback-provided
theme: kotlin
type: enhancement
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Background
Context Parameters were introduced in Kotlin 2.1.20 and are currently in Beta status in Kotlin 2.2.0 under the flag -Xcontext-parameters (announcement)
Issue
Spring's KotlinReflectionParameterNameDiscoverer cannot detect Context Parameters in Kotlin methods. The kotlinFunction property returns incomplete results - context parameters are completely absent from the reflection data.
Use Case
I'm migrating from Context Receivers to Context Parameters for implementing security via HandlerMethodArgumentResolver. My implementation:
- Uses a custom
UserContextclass as a context parameter - Injects it into controller handler methods
- Propagates it through service method calls
Technical Details
- Current implementation relies on: KotlinReflectionParameterNameDiscoverer.java#L46
- Related Kotlin issues:
- KT-78752: Context Parameters missing in reflection - I'm asking to fix
kotlinFunction, hopefully in 2.1.22/2.2.10 - KT-74529: Context parameters support in reflection - Card about support of context parameters targeting 2.2.20
- KT-78752: Context Parameters missing in reflection - I'm asking to fix
Expected
- Track support for Context Parameters in Spring Framework (if KT-78752 will be resolved)
- Add support for the new parameter kind coming in Kotlin 2.2.20 when reflection API is available
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.