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

PropertyOrFieldReference throws ClassCastException [SPR-13247] #17838

Closed
spring-projects-issues opened this issue Jul 17, 2015 · 1 comment
Closed
Assignees
Labels
in: core status: backported type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 17, 2015

Franklin Bristow opened SPR-13247 and commented

Hi,
I discovered this issue when I was debugging a problem that I was encountering using Thymeleaf. I describe the issue that I encountered with Thymeleaf here: http://forum.thymeleaf.org/Expression-Caching-td4029136.html

The problem actually seems to boil down to how PropertyOrFieldReference#readProperty expects a PropertyAccessor to behave when the class type of contextObject has changed.

The situation that I'm running in to is that when I evaluate a Map with a SpEL expression, then try to evaluate a different class with the same parsed SpEL expression, the cachedReadAccessor in PropertyOrFieldReference is of type MapAccessor. MapAccessor#read is expecting that the argument passed to it is of type Map (it doesn't check), but when the type is not of type Map, it just throws ClassCastException because it's trying to cast to Map.

PropertyOrFieldReference has a comment explaining that it can handle class-type changes, but it's expecting the PropertyAccessor to throw AccessException. Since MapAccessor is just throwing ClassCastException, the exception just goes all the way up the stack, even though the expected behaviour is to just try a different PropertyAccessor.

I've attached some code that demonstrates the behaviour. It contains some thymeleaf code, but that's the context that I'm using it in that demonstrates the behaviour.


Affects: 4.1.7

Attachments:

Issue Links:

  • #17614 NPE in PropertyOrFieldReference due to concurrency issue when caching SpelExpression objects

Referenced from: commits 34a81b6, ac4c278

Backported to: 4.1.8

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 20, 2015

Juergen Hoeller commented

PropertyOrFieldReference defensively catches Exception now, catching ClassCastException, IllegalArgumentException and the like as well.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: backported type: bug
Projects
None yet
Development

No branches or pull requests

2 participants