-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Unsafe double-checked locking in SpelExpression#compileExpression #24265
Comments
@aclement, can you please take a look at this? |
Yep @PascalSchumacher I think you are right. Syncing on string has a chance to cause trouble (but I'm not aware of anyone reporting it actually did). Also, I think ideally we should make compiledAst volatile - although I don't think that causes us breaking issues other than not being optimal in this case (I am not an expert on java concurrency though!). We just might compile the same expression twice (the latest one winning), but It think there is no harm in that other than creating an unnecessary duplicate class representing the compiled expression, things shouldn't blow up. Want to submit a PR? |
@aclement @PascalSchumacher Thanks for the report and for the analysis! I'll take care of this, aligning it with similar arrangements in other parts of the codebase, and also backporting it. So no need for a PR, however, happy to take any further insight into account... |
The double-checked locking
SpelExpression#compileExpression
does not seem to be thread safe, becausecompiledAst
is notvolatile
, see:https://github.com/spring-projects/spring-framework/blob/master/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java#L506
Or am I missing something?
Edit:
Also
SpelExpression#compileExpression
usesthis.expression
(aString
) as a lock object. Shouldn't this be avoided, as Strings objects are shared throughout the program?The text was updated successfully, but these errors were encountered: