Affects: 6.1.3
After upgrading from spring version 6.1.2 to version 6.1.3, I can in some cases no longer use method parameter names in spel expressions specified in the key
parameter of spring's @CachePut
annotation. The concrete situation where this no longer works is when using the annotation on spring data @Repository
-annotated interfaces, when overriding the save
method of the MongoRepository
interface. The reason is that spring no longer injects the method parameter names into the spel context, because it no longer identifies the annotated method as the "most specific method" but instead the overridden method from the MongoRepository
.
A concrete example:
@Repository
interface MyPojoRepository: MongoRepository<MyPojo, String> {
@CachePut(cacheNames = ["some-cache"], key = "#pojo.id")
override fun <S: MyPojo> save(pojo: S): S
}
When calling the save
method, I get the following error since spring 6.1.3: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'id' cannot be found on null
.
I only saw this issue when using spring data and spring caching as described above, but it looks to me as if the issue is not due to those spring libraries, but to a change in spring's AopUtils
. I traced the problem down (to my best knowledge) to commit 419e34e571b975adfc1355abd551f19c0c682cd9, which changes the implementation of AopUtils.getMostSpecificMethod
; before that commit, the method returned the save
method from MyPojoRepository
, after that commit, the method returned the overridden save
method from MongoRepository
. In consequence, with 6.1.2 the method parameter name pojo
from my own method can still be used in the spel expression, with 6.1.2 it can no longer be used.
To be honest, I do not have knowledge in how AopUtils.getMostSpecificMethod
works, but to me it looks as if 419e34e571b975adfc1355abd551f19c0c682cd9, while fixing some issue, also introduced the new issue I described above.
If I am missing any relevant information in this issue, please give me a ping, and I will try to provide it.
Comment From: jhoeller
This looks like a duplicate of #32087 which has been fixed for 6.1.4 already. Feel free to give a 6.1.4 snapshot a try!
6.1.4 is scheduled for release next week.
Comment From: hsudbrock
Thanks for the hint - this looks like a perfect match. I will give it a try!