Affects: 5.0.4
When iterating on a collection, both Selection and Projection set a variable called index
that contains the index of the current element.
I would expect this variable to be usable in SpEL, e.g. for filtering one list based on elements of another list (or any other criterion that takes the index into account).
However, there doesn't seem to be any way to reference it.
The only code that makes use of VariableScope
is never called.
Am I missing something or is this feature not really complete?
Comment From: sbrannen
Hi @peterschubert,
Thanks for raising the issue and apologies for the belated reply.
Am I missing something or is this feature not really complete?
No, you're not missing anything.
The team originally considered providing support for local variables in SpEL expressions, and that's evident by the code you noticed as well as various other methods in ExpressionState
.
However, the Spring Framework does not make use of the local variable support in ExpressionState
other than in a few unit tests.
If local variables were supported in the AST and evaluation, I believe you would have been able to access that index
variable as $index
, but unfortunately that's not the case.
In light of that, I am closing this issue.