-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
@Async
spoils references to @Value
variables from final
methods of the class
#33939
Comments
I found |
Hi @taqqanori, Here’s my understanding: When you use the @async annotation, Spring creates a proxy object for the bean of the target class. Since the proxy is created using CGLIB, it generates a subclass of the target class and overrides the non-final methods to enable interception. As a result, when you invoke a final method, the call is handled directly by the proxy object itself, rather than being delegated to the original (target) object. Additionally, the proxy object does not copy the field values from the original target object. |
Hi @ZLATAN628 Thank you for the detailed explanation. Very interesting. |
@taqqanori Generating proxy objects through cglib will skip the final modified class or method, but the log level is: trace, so you may not be able to see it. The corresponding code location is: org.springframework.context.annotation.ConfigurationClassEnhancer.BeanMethodInterceptor#enhanceFactoryBean |
@lucky8987 |
When a method is
@Async
,@Value
variable becomesnull
in any otherfinal
methods (and, the@Async
method itself if it'sfinal
) of the class.Is this unavoidable due to Java Reflection spec?
Reproduction code here: https://github.com/taqqanori/spring-async-bug.
Reproduction code in short
spring.application.name=demo
Output
Environment
Thanks.
The text was updated successfully, but these errors were encountered: