In the production environment, I discovered that AdvisedSupport#methodCache
contains two "identical" keys, both corresponding to the same method object.
Experimentally, I found that the methodCache
established during bean initialization is practically useless. During actual method invocation, the interceptor chain retrieved via methodCache.get(cacheKey)
turns out to be empty. Thus, the interceptor chain is fetched again using advisorChainFactory
and then placed into the methodCache
. This means that the initialization logic related to getInterceptorsAndDynamicInterceptionAdvice
will not only execute during bean initialization but also during the first method invocation.
Returning to the issue itself, since each call to getClass().getDeclaredMethods()[0]
results in a Method
object that, when compared using ==
, returns false
(even if it's the same method), I believe the equals
method of MethodCacheKey
is poorly designed.
Comment From: PleaseGiveMeTheCoke
@bclozel Hello, the code and README in this repository provide a more detailed description of the issue. I would be very grateful if you could help confirm this problem. https://github.com/PleaseGiveMeTheCoke/spring-aop-methodCache
Comment From: sbrannen
Hi @PleaseGiveMeTheCoke,
Congratulations on submitting your first issue for the Spring Framework! 👍
And thanks for the detailed explanation and sample project.
In commit 320831b18ad7e8f0d0f0e9072f287ba699e96a21, I introduced DefaultAdvisorAutoProxyCreatorTests
which is a simplified version of your sample project that reproduces the issue. The second assertion verifies that the invocation count for the matches()
method isEqualTo(3)
; whereas, I believe that that should rather be 2 for a static pointcut (i.e., remain unchanged).
In addition, I pushed a proposed enhancement for MethodCacheKey
to the following feature branch, which I'll discuss with @jhoeller before deciding if/where to merge it.
https://github.com/spring-projects/spring-framework/compare/main...sbrannen:spring-framework:issues/gh-33915-AdvisedSupport-MethodCacheKey
As a side note, this is also related to:
-
32586
Regards,
Sam