You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SPEL PropertyOrFieldReference makes Expressions unsafe to use from multiple threads. Cached accessor is replaced in the middle of method in case of mismatching resolution, possibly causing confusion for another thread.
I have attached a small test below which sometimes manages to reproduce the issue. Unfortunately, as it is race condition, it happens only sometimes - on my dual core machine, about 50% of times. Anyway, code review can spot the bug without the need for reproducing it.
In this case I have chosen degenerated example, where field is replaced with accessor method. Unfortunately, entire package seems to be quite thread unsafe - ReflectionPropertyReaderExecutor has non-final fields, which, due to lack of synchronization, can leak as nulls to different threads, possibly causing exceptions even on simples cases of accessing type of object.
Here is the example exception I got from the test case
org.springframework.expression.spel.SpelException: EL1034E:(pos 0): A problem occurred whilst attempting to access the property 'val1':
'Unable to access property 'val1' through getter'
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:125)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:53)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:48)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:52)
at org.springframework.expression.spel.SpelExpression.getValue(SpelExpression.java:65)
at org.springframework.expression.spel.ReuseTest$1.run(ReuseTest.java:20)
Caused by: org.springframework.expression.AccessException: Unable to access property 'val1' through getter
at org.springframework.expression.spel.reflection.ReflectionPropertyReaderExecutor.execute(ReflectionPropertyReaderExecutor.java:35)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:107)
... 5 more
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@e53220
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.expression.spel.reflection.ReflectionPropertyReaderExecutor.execute(ReflectionPropertyReaderExecutor.java:33)
... 6 more
Artur Biesiadowski opened SPR-5374 and commented
SPEL PropertyOrFieldReference makes Expressions unsafe to use from multiple threads. Cached accessor is replaced in the middle of method in case of mismatching resolution, possibly causing confusion for another thread.
I have attached a small test below which sometimes manages to reproduce the issue. Unfortunately, as it is race condition, it happens only sometimes - on my dual core machine, about 50% of times. Anyway, code review can spot the bug without the need for reproducing it.
In this case I have chosen degenerated example, where field is replaced with accessor method. Unfortunately, entire package seems to be quite thread unsafe - ReflectionPropertyReaderExecutor has non-final fields, which, due to lack of synchronization, can leak as nulls to different threads, possibly causing exceptions even on simples cases of accessing type of object.
Affects: 3.0 M1
Attachments:
The text was updated successfully, but these errors were encountered: