spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.28k stars 37.62k forks source link

`IndexAccessor` cannot support custom `Collection` target type #32736

Closed sbrannen closed 2 weeks ago

sbrannen commented 2 weeks ago

Overview

Due to the current implementation of SpEL's Indexer, an IndexAccessor cannot provide custom support for a Collection target type.

The reason is that Indexer owns the Collection target type.

https://github.com/spring-projects/spring-framework/blob/a3afe51c9fa7d0f9fe3e59b84219f6ab3eb9e986/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java#L234-L241

We should be able to ensure that a custom IndexAccessor can provide support for a Collection target type by separating our built-in List and Collection support and applying the built-in Collection support after custom index accessors have been applied, analogous to what we did in #32706. The built-in List support should still be applied before custom index accessors and therefore remain unchanged.

Related Issues