Merge branch '7.0.x'

This commit is contained in:
Sam Brannen
2026-06-27 16:19:38 +02:00
2 changed files with 10 additions and 23 deletions
@@ -16,7 +16,6 @@
package org.springframework.expression.spel;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
@@ -183,7 +182,7 @@ class MethodInvocationTests extends AbstractExpressionTests {
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(new TestObject());
LocalFilter filter = new LocalFilter();
context.registerMethodFilter(TestObject.class,filter);
context.registerMethodFilter(TestObject.class, filter);
// Filter will be called but not do anything, so first doit() will be invoked
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
@@ -209,7 +208,7 @@ class MethodInvocationTests extends AbstractExpressionTests {
// check de-registration works
filter.filterCalled = false;
context.registerMethodFilter(TestObject.class,null);//clear filter
context.registerMethodFilter(TestObject.class, null); // clear filter
context.setRootObject(new TestObject());
expr = (SpelExpression) parser.parseExpression("doit(1)");
result = expr.getValue(context, String.class);
@@ -447,32 +446,20 @@ class MethodInvocationTests extends AbstractExpressionTests {
// Simple filter
static class LocalFilter implements MethodFilter {
public boolean removeIfNotAnnotated = false;
boolean removeIfNotAnnotated = false;
public boolean filterCalled = false;
boolean filterCalled = false;
private boolean isAnnotated(Method method) {
Annotation[] anns = method.getAnnotations();
if (anns == null) {
return false;
}
for (Annotation ann : anns) {
String name = ann.annotationType().getName();
if (name.endsWith("Anno")) {
return true;
}
}
return false;
return method.isAnnotationPresent(Anno.class);
}
@Override
public List<Method> filter(List<Method> methods) {
filterCalled = true;
this.filterCalled = true;
List<Method> forRemoval = new ArrayList<>();
for (Method method: methods) {
if (removeIfNotAnnotated && !isAnnotated(method)) {
forRemoval.add(method);
}
if (this.removeIfNotAnnotated) {
methods.stream().filter(method -> !isAnnotated(method)).forEach(forRemoval::add);
}
for (Method method: forRemoval) {
methods.remove(method);
@@ -495,7 +482,7 @@ class MethodInvocationTests extends AbstractExpressionTests {
@Anno
public String doit(double d) {
return "double "+d;
return "double " + d;
}
}