Fix SpEL compilation of static method/property/field operations
Before this change the compilation of a method reference or property/field
access was not properly cleaning up the stack if compilation meant
calling a static method or accessing a static field. In these cases there
is no need for a target object on the stack and it should be removed if
present. For a simple expression it is harmless since the end result of
the expression is the thing on the top of the stack, but for nested
expressions if the inner expression suffered this issue, the outer
expression can find itself operating on the wrong element.
The particular issue covered the case of a static field access but this
fix (and associated tests) cover static method, property and field access.
Issue: SPR-13781
(cherry picked from commit a28fc76)
pull/941/head
Andy Clement10 years agocommitted byJuergen Hoeller
@ -66,8 +69,6 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -66,8 +69,6 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -122,7 +123,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -122,7 +123,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
}
publicMembergetLastReadInvokerPair(){
returnlastReadInvokerPair.member;
returnthis.lastReadInvokerPair.member;
}
@Override
@ -165,7 +166,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -165,7 +166,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
thrownewAccessException("Unable to access property '"+name+"' through getter",ex);
thrownewAccessException("Unable to access property '"+name+"' through getter method",ex);
}
}
}
@ -187,12 +188,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -187,12 +188,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
thrownewAccessException("Unable to access field: "+name,ex);
thrownewAccessException("Unable to access field '"+name+"'",ex);
}
}
}
thrownewAccessException("Neither getter nor field found for property '"+name+"'");
thrownewAccessException("Neither getter method nor field found for property '"+name+"'");
}
@Override
@ -240,7 +241,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -240,7 +241,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -262,7 +263,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -262,7 +263,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return;
}
catch(Exceptionex){
thrownewAccessException("Unable to access property '"+name+"' through setter",ex);
thrownewAccessException("Unable to access property '"+name+"' through setter method",ex);
}
}
}
@ -283,12 +284,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -283,12 +284,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return;
}
catch(Exceptionex){
thrownewAccessException("Unable to access field: "+name,ex);
thrownewAccessException("Unable to access field '"+name+"'",ex);
}
}
}
thrownewAccessException("Neither setter nor field found for property '"+name+"'");
thrownewAccessException("Neither setter method nor field found for property '"+name+"'");
@ -469,11 +470,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -469,11 +470,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -497,6 +498,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -497,6 +498,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -577,16 +579,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -577,16 +579,8 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -599,10 +593,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -599,10 +593,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -621,30 +617,31 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -621,30 +617,31 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
thrownewAccessException("Unable to access field: "+name,ex);
thrownewAccessException("Unable to access field '"+name+"'",ex);
}
}
thrownewAccessException("Neither getter nor field found for property '"+name+"'");
}
@Override
@ -665,11 +662,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -665,11 +662,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@Override
publicClass<?>getPropertyType(){
if(this.memberinstanceofField){
return((Field)this.member).getType();
if(this.memberinstanceofMethod){
return((Method)this.member).getReturnType();
}
else{
return((Method)this.member).getReturnType();
return((Field)this.member).getType();
}
}
@ -677,22 +674,31 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@@ -677,22 +674,31 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
@ -2008,6 +2008,103 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@@ -2008,6 +2008,103 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@ -4353,4 +4450,29 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
@@ -4353,4 +4450,29 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {