From 80fb8ea8137975e072c7611f5ae197cadd470da7 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:04:41 +0200 Subject: [PATCH] Avoid unnecessary compilation attempts in SpEL's Indexer Closes gh-32677 --- .../org/springframework/expression/spel/ast/Indexer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 5abc3bbc770..be10fbfed39 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 @@ -355,8 +355,11 @@ public class Indexer extends SpelNodeImpl { @Override public boolean isCompilable() { + if (this.exitTypeDescriptor == null) { + return false; + } if (this.indexedType == IndexedType.ARRAY) { - return (this.exitTypeDescriptor != null && this.arrayTypeDescriptor != null); + return (this.arrayTypeDescriptor != null); } SpelNodeImpl index = this.children[0]; if (this.indexedType == IndexedType.LIST) { @@ -792,10 +795,11 @@ public class Indexer extends SpelNodeImpl { this.evaluationContext, this.targetObject, this.name); } updatePropertyReadState(accessor, this.name, targetType); + TypedValue result = accessor.read(this.evaluationContext, this.targetObject, this.name); if (accessor instanceof CompilablePropertyAccessor compilablePropertyAccessor) { setExitTypeDescriptor(CodeFlow.toDescriptor(compilablePropertyAccessor.getPropertyType())); } - return accessor.read(this.evaluationContext, this.targetObject, this.name); + return result; } } }