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

SPEL PropertyOrFieldReference not threadsafe [SPR-5374] #10047

Closed
spring-projects-issues opened this issue Dec 22, 2008 · 1 comment
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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:

@spring-projects-issues
Copy link
Collaborator Author

Artur Biesiadowski commented

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

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

No branches or pull requests

2 participants