-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide guidelines for using Kotlin properties with proxies (@RequestScope
and similar use cases)
#32287
Comments
This is due to Kotlin properties translating to @RequestScope
@Component
class RequestContext (var messageId:String? = null) I will check with the team if an error should be thrown for that use case instead of silently ignoring it ( |
Please note that we log a message at If you set the log level for
However, I concede that it's not intuitive to check debug log messages for |
Removing In the future, an error might help others identify this issue sooner. Thanks for the quick responses! |
@RequestScope
and similar use cases)
After discussing this issue with the team, I can share that changing the behavior or differentiate valid use cases from obvious errors is much more complex and nuanced than it seems. As a consequence, I turn this issue into a documentation one where I will share the guidelines exposed above, and will delegate to #26729 some potential behavior changes. |
@sdeleuze Can you share some examples, where this is valid? Why not have the valid use cases opt-in explicitly and barring it by default? |
Problem statement
Hi team,
I noticed a discrepancy in behavior when using the
@RequestScope
annotation.Per the documentation I expect each request to produce a new bean with a fresh set of properties.
However, I observed two different outcomes, depending on the language of the model, Java vs Kotlin.
Example
Spring boot version: 3.2.2
I tested this by making repeated request to
http://localhost:8080/uniqueRequest
When using a Java model, I noticed the messageId is appropriately assigned when chosen by chance and appropriately cleared/set to empty when not chosen by chance on each subsequent request.
When using a Kotlin model, I noticed the messageId is appropriately assigned when chosen by chance and the property is unexpectedly carried over when not chosen by chance on each subsequent request.
RequestContextConfig.kt
HelloController.kt
Here are the two models, which show the different behaviors
Kotlin
Java
Observed output
Here are the results when making subsequent calls with each model (Kotlin and Java)
"Random hit" and "random not hit" indicates whether the random if statement in the controller was evaluated to true. (This was verified with a breakpoint)
Kotlin
Java
Why would the property be cached/saved when the model is defined with Kotlin?
The text was updated successfully, but these errors were encountered: