Skip to content

PropertyOrFieldReference throws ClassCastException [SPR-13247] #17838

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 34a81b6, ac4c278

Backported to: 4.1.8

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions