From ad886503f12d42f9524b9136fc4440a4faeed0d9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 7 May 2013 21:56:17 +0200 Subject: [PATCH] Revised ReflectiveMethodResolver to properly handle any kind of List returned from a MethodFilter Issue: SPR-10392 --- .../support/ReflectiveMethodResolver.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java index 12cd86d36b..fbd0b77bca 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java @@ -42,8 +42,8 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; /** - * Reflection-based {@link MethodResolver} used by default in - * {@link StandardEvaluationContext} unless explicit method resolvers have been specified. + * Reflection-based {@link MethodResolver} used by default in {@link StandardEvaluationContext} + * unless explicit method resolvers have been specified. * * @author Andy Clement * @author Juergen Hoeller @@ -63,7 +63,6 @@ public class ReflectiveMethodResolver implements MethodResolver { public ReflectiveMethodResolver() { - } /** @@ -99,7 +98,8 @@ public class ReflectiveMethodResolver implements MethodResolver { // If a filter is registered for this type, call it MethodFilter filter = (this.filters != null ? this.filters.get(type) : null); if (filter != null) { - methods = filter.filter(methods); + List filtered = filter.filter(methods); + methods = (filtered instanceof ArrayList ? filtered : new ArrayList(filtered)); } // Sort methods into a sensible order @@ -119,7 +119,7 @@ public class ReflectiveMethodResolver implements MethodResolver { } // Remove duplicate methods (possible due to resolved bridge methods) - methods = new ArrayList(new LinkedHashSet(methods)); + Set methodsToIterate = new LinkedHashSet(methods); Method closeMatch = null; int closeMatchDistance = Integer.MAX_VALUE; @@ -127,7 +127,7 @@ public class ReflectiveMethodResolver implements MethodResolver { Method matchRequiringConversion = null; boolean multipleOptions = false; - for (Method method : methods) { + for (Method method : methodsToIterate) { if (method.getName().equals(name)) { Class[] paramTypes = method.getParameterTypes(); List paramDescriptors = new ArrayList(paramTypes.length); @@ -148,9 +148,10 @@ public class ReflectiveMethodResolver implements MethodResolver { return new ReflectiveMethodExecutor(method, null); } else if (matchInfo.kind == ReflectionHelper.ArgsMatchKind.CLOSE) { - if (!useDistance) { + if (!this.useDistance) { closeMatch = method; - } else { + } + else { int matchDistance = ReflectionHelper.getTypeDifferenceWeight(paramDescriptors, argumentTypes); if (matchDistance type, Object targetObject) { - if(targetObject instanceof Class) { + if (targetObject instanceof Class) { Set methods = new HashSet(); methods.addAll(Arrays.asList(getMethods(type))); methods.addAll(Arrays.asList(getMethods(targetObject.getClass()))); @@ -211,9 +212,9 @@ public class ReflectiveMethodResolver implements MethodResolver { /** * Return the set of methods for this type. The default implementation returns the - * result of Class#getMethods for the given {@code type}, but subclasses may override - * in order to alter the results, e.g. specifying static methods declared elsewhere. - * + * result of {@link Class#getMethods()} for the given {@code type}, but subclasses + * may override in order to alter the results, e.g. specifying static methods + * declared elsewhere. * @param type the class for which to return the methods * @since 3.1.1 */