Skip to content

Commit 56634c9

Browse files
artembilangaryrussell
authored andcommitted
GH-3912: Handler: ignore Groovy generated methods
Fixes #3912 **Cherry-pick to `5.5.x`**
1 parent 3602a0f commit 56634c9

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
5353
import org.springframework.core.MethodParameter;
5454
import org.springframework.core.ParameterNameDiscoverer;
55+
import org.springframework.core.annotation.AnnotatedElementUtils;
5556
import org.springframework.core.annotation.AnnotationAttributes;
5657
import org.springframework.core.annotation.AnnotationUtils;
5758
import org.springframework.core.convert.ConversionFailedException;
@@ -785,44 +786,24 @@ else if (!Modifier.isPublic(method1.getModifiers())) {
785786
ambiguousFallbackType, ambiguousFallbackMessageGenericType, matchesAnnotation, handlerMethod1);
786787
}
787788

788-
}, new UniqueMethodFilter(targetClass));
789+
}, ((ReflectionUtils.MethodFilter) this::isHandlerMethod).and(new UniqueMethodFilter(targetClass)));
789790

790791
if (candidateMethods.isEmpty() && candidateMessageMethods.isEmpty() && fallbackMethods.isEmpty()
791792
&& fallbackMessageMethods.isEmpty()) {
792793
findSingleSpecificMethodOnInterfacesIfProxy(candidateMessageMethods, candidateMethods);
793794
}
794795
}
795796

796-
@Nullable
797-
private HandlerMethod obtainHandlerMethodIfAny(Method methodToProcess) {
798-
HandlerMethod handlerMethodToUse = null;
799-
if (isMethodEligible(methodToProcess)) {
800-
try {
801-
handlerMethodToUse = createHandlerMethod(
802-
AopUtils.selectInvocableMethod(methodToProcess, ClassUtils.getUserClass(this.targetObject)));
803-
}
804-
catch (Exception ex) {
805-
LOGGER.debug(ex, "Method [" + methodToProcess + "] is not eligible for Message handling.");
806-
return null;
807-
}
808-
809-
if (AnnotationUtils.getAnnotation(methodToProcess, Default.class) != null) {
810-
Assert.state(this.defaultHandlerMethod == null,
811-
() -> "Only one method can be @Default, but there are more for: " + this.targetObject);
812-
this.defaultHandlerMethod = handlerMethodToUse;
813-
}
814-
}
815-
816-
return handlerMethodToUse;
817-
}
818-
819-
private boolean isMethodEligible(Method methodToProcess) {
820-
return !(methodToProcess.isBridge() || // NOSONAR boolean complexity
821-
isMethodDefinedOnObjectClass(methodToProcess) ||
822-
methodToProcess.getDeclaringClass().equals(Proxy.class) ||
823-
(this.requiresReply && void.class.equals(methodToProcess.getReturnType())) ||
824-
(this.methodName != null && !this.methodName.equals(methodToProcess.getName())) ||
825-
(this.methodName == null && isPausableMethod(methodToProcess)));
797+
private boolean isHandlerMethod(Method method) {
798+
Class<?> declaringClass = method.getDeclaringClass();
799+
return !(method.isSynthetic() ||
800+
ReflectionUtils.isObjectMethod(method) ||
801+
AnnotatedElementUtils.isAnnotated(method, "groovy.transform.Generated") ||
802+
declaringClass.getName().equals("groovy.lang.GroovyObject") ||
803+
declaringClass.equals(Proxy.class) ||
804+
(this.requiresReply && void.class.equals(method.getReturnType())) ||
805+
(this.methodName != null && !this.methodName.equals(method.getName())) ||
806+
(this.methodName == null && isPausableMethod(method)));
826807
}
827808

828809
private boolean isPausableMethod(Method pausableMethod) {
@@ -837,6 +818,27 @@ private boolean isPausableMethod(Method pausableMethod) {
837818
return pausable;
838819
}
839820

821+
@Nullable
822+
private HandlerMethod obtainHandlerMethodIfAny(Method methodToProcess) {
823+
HandlerMethod handlerMethodToUse;
824+
try {
825+
handlerMethodToUse = createHandlerMethod(
826+
AopUtils.selectInvocableMethod(methodToProcess, ClassUtils.getUserClass(this.targetObject)));
827+
}
828+
catch (Exception ex) {
829+
LOGGER.debug(ex, "Method [" + methodToProcess + "] is not eligible for Message handling.");
830+
return null;
831+
}
832+
833+
if (AnnotationUtils.getAnnotation(methodToProcess, Default.class) != null) {
834+
Assert.state(this.defaultHandlerMethod == null,
835+
() -> "Only one method can be @Default, but there are more for: " + this.targetObject);
836+
this.defaultHandlerMethod = handlerMethodToUse;
837+
}
838+
839+
return handlerMethodToUse;
840+
}
841+
840842
private void populateHandlerMethod(Map<Class<?>, HandlerMethod> candidateMethods,
841843
Map<Class<?>, HandlerMethod> candidateMessageMethods, Map<Class<?>, HandlerMethod> fallbackMethods,
842844
Map<Class<?>, HandlerMethod> fallbackMessageMethods, AtomicReference<Class<?>> ambiguousFallbackType,
@@ -1041,8 +1043,7 @@ private HandlerMethod findClosestMatch(Class<?> payloadType) {
10411043

10421044
private static boolean isMethodDefinedOnObjectClass(Method method) {
10431045
return method != null && // NOSONAR
1044-
(method.getDeclaringClass().equals(Object.class) || ReflectionUtils.isEqualsMethod(method) ||
1045-
ReflectionUtils.isHashCodeMethod(method) || ReflectionUtils.isToStringMethod(method) ||
1046+
(ReflectionUtils.isObjectMethod(method) ||
10461047
AopUtils.isFinalizeMethod(method) || (method.getName().equals("clone")
10471048
&& method.getParameterTypes().length == 0));
10481049
}

0 commit comments

Comments
 (0)