Description
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:
- NPE in PropertyOrFieldReference due to concurrency issue when caching SpelExpression objects [SPR-13023] #17614 NPE in PropertyOrFieldReference due to concurrency issue when caching SpelExpression objects
Referenced from: commits 34a81b6, ac4c278
Backported to: 4.1.8