Skip to content
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

Behavior of AopUtils#getMostSpecificMethod in some cases no longer returns the most specific method #32224

Closed
hsudbrock opened this issue Feb 8, 2024 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: regression A bug that is also a regression

Comments

@hsudbrock
Copy link

hsudbrock commented Feb 8, 2024

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 419e34e, 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 419e34e, 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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 8, 2024
@jhoeller
Copy link
Contributor

jhoeller commented Feb 8, 2024

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.

@jhoeller jhoeller closed this as completed Feb 8, 2024
@jhoeller jhoeller added status: duplicate A duplicate of another issue type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 8, 2024
@hsudbrock
Copy link
Author

Thanks for the hint - this looks like a perfect match. I will give it a try!

@jhoeller jhoeller self-assigned this Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants