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 UserContext
class 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
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
Comment From: sdeleuze
Let's explore that when Kotlin reflection will be fixed.