PropertyOrFieldReference throws ClassCastException [SPR-13247] #17838
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
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 aPropertyAccessor
to behave when the class type ofcontextObject
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, thecachedReadAccessor
inPropertyOrFieldReference
is of typeMapAccessor
.MapAccessor#read
is expecting that the argument passed to it is of typeMap
(it doesn't check), but when the type is not of typeMap
, it just throwsClassCastException
because it's trying to cast toMap
.PropertyOrFieldReference
has a comment explaining that it can handle class-type changes, but it's expecting thePropertyAccessor
to throwAccessException
. SinceMapAccessor
is just throwingClassCastException
, the exception just goes all the way up the stack, even though the expected behaviour is to just try a differentPropertyAccessor
.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
The text was updated successfully, but these errors were encountered: