diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java index 63e568a10b..e290102ceb 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AstUtils.java @@ -33,6 +33,25 @@ import org.springframework.util.ObjectUtils; */ abstract class AstUtils { + /** + * Determine the set of accessors that should be used to try to access an + * element on the specified target object. + *

Delegates to {@link #getAccessorsToTry(Class, List)} with the type of + * the supplied target object. + * @param targetObject the object upon which element access is being attempted + * @param accessors the list of element accessors to process + * @return a list of accessors that should be tried in order to access the + * element on the specified target type, or an empty list if no suitable + * accessor could be found + * @since 6.2 + */ + static List getAccessorsToTry( + @Nullable Object targetObject, List accessors) { + + Class targetType = (targetObject != null ? targetObject.getClass() : null); + return getAccessorsToTry(targetType, accessors); + } + /** * Determine the set of accessors that should be used to try to access an * element on the specified target type. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index c513d8f6f4..4fe15aacbe 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -246,7 +246,8 @@ public class Indexer extends SpelNodeImpl { // Check for a custom IndexAccessor. EvaluationContext evalContext = state.getEvaluationContext(); - List accessorsToTry = getIndexAccessorsToTry(target, evalContext.getIndexAccessors()); + List accessorsToTry = + AstUtils.getAccessorsToTry(target, evalContext.getIndexAccessors()); if (accessMode.supportsReads) { try { for (IndexAccessor indexAccessor : accessorsToTry) { @@ -444,22 +445,6 @@ public class Indexer extends SpelNodeImpl { return (obj instanceof Class clazz ? clazz : obj.getClass()); } - /** - * Determine the set of index accessors that should be used to try to access - * an index on the specified context object. - *

Delegates to {@link AstUtils#getAccessorsToTry(Class, List)}. - * @param targetObject the object upon which index access is being attempted - * @param indexAccessors the list of index accessors to process - * @return a list of accessors that should be tried in order to access the - * index, or an empty list if no suitable accessor could be found - */ - private static List getIndexAccessorsToTry( - @Nullable Object targetObject, List indexAccessors) { - - Class targetType = (targetObject != null ? targetObject.getClass() : null); - return AstUtils.getAccessorsToTry(targetType, indexAccessors); - } - /** * Tracks state when the {@code Indexer} is being used as a {@link PropertyAccessor}. @@ -740,8 +725,8 @@ public class Indexer extends SpelNodeImpl { // we need to reset our cached state. Indexer.this.cachedPropertyReadState = null; } - List accessorsToTry = AstUtils.getAccessorsToTry(targetType, - this.evaluationContext.getPropertyAccessors()); + List accessorsToTry = + AstUtils.getAccessorsToTry(targetType, this.evaluationContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canRead(this.evaluationContext, this.targetObject, this.name)) { if (accessor instanceof ReflectivePropertyAccessor reflectivePropertyAccessor) { @@ -783,8 +768,8 @@ public class Indexer extends SpelNodeImpl { // we need to reset our cached state. Indexer.this.cachedPropertyWriteState = null; } - List accessorsToTry = AstUtils.getAccessorsToTry(targetType, - this.evaluationContext.getPropertyAccessors()); + List accessorsToTry = + AstUtils.getAccessorsToTry(targetType, this.evaluationContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canWrite(this.evaluationContext, this.targetObject, this.name)) { accessor.write(this.evaluationContext, this.targetObject, this.name, newValue); @@ -998,7 +983,7 @@ public class Indexer extends SpelNodeImpl { Indexer.this.cachedIndexReadState = null; } List accessorsToTry = - getIndexAccessorsToTry(this.target, this.evaluationContext.getIndexAccessors()); + AstUtils.getAccessorsToTry(this.target, this.evaluationContext.getIndexAccessors()); for (IndexAccessor indexAccessor : accessorsToTry) { if (indexAccessor.canRead(this.evaluationContext, this.target, this.index)) { TypedValue result = indexAccessor.read(this.evaluationContext, this.target, this.index); @@ -1050,7 +1035,7 @@ public class Indexer extends SpelNodeImpl { Indexer.this.cachedIndexWriteState = null; } List accessorsToTry = - getIndexAccessorsToTry(this.target, this.evaluationContext.getIndexAccessors()); + AstUtils.getAccessorsToTry(this.target, this.evaluationContext.getIndexAccessors()); for (IndexAccessor indexAccessor : accessorsToTry) { if (indexAccessor.canWrite(this.evaluationContext, this.target, this.index)) { indexAccessor.write(this.evaluationContext, this.target, this.index, newValue); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java index 2aab75f9c6..5907e2dde0 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java @@ -201,7 +201,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl { } List accessorsToTry = - getPropertyAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); + AstUtils.getAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); // Go through the accessors that may be able to resolve it. If they are a cacheable accessor then // get the accessor and use it. If they are not cacheable but report they can read the property // then ask them to read it @@ -259,7 +259,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl { } List accessorsToTry = - getPropertyAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); + AstUtils.getAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); try { for (PropertyAccessor accessor : accessorsToTry) { if (accessor.canWrite(evalContext, targetObject, name)) { @@ -284,7 +284,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl { Object targetObject = contextObject.getValue(); if (targetObject != null) { List accessorsToTry = - getPropertyAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); + AstUtils.getAccessorsToTry(targetObject, evalContext.getPropertyAccessors()); for (PropertyAccessor accessor : accessorsToTry) { try { if (accessor.canWrite(evalContext, targetObject, name)) { @@ -299,21 +299,6 @@ public class PropertyOrFieldReference extends SpelNodeImpl { return false; } - /** - * Determine the set of property accessors that should be used to try to - * access a property on the specified context object. - *

Delegates to {@link AstUtils#getAccessorsToTry(Class, List)}. - * @param targetObject the object upon which property access is being attempted - * @return a list of accessors that should be tried in order to access the - * property, or an empty list if no suitable accessor could be found - */ - private List getPropertyAccessorsToTry( - @Nullable Object targetObject, List propertyAccessors) { - - Class targetType = (targetObject != null ? targetObject.getClass() : null); - return AstUtils.getAccessorsToTry(targetType, propertyAccessors); - } - @Override public boolean isCompilable() { return (this.cachedReadAccessor instanceof CompilablePropertyAccessor compilablePropertyAccessor &&