53
53
import org .springframework .core .LocalVariableTableParameterNameDiscoverer ;
54
54
import org .springframework .core .MethodParameter ;
55
55
import org .springframework .core .ParameterNameDiscoverer ;
56
+ import org .springframework .core .annotation .AnnotatedElementUtils ;
56
57
import org .springframework .core .annotation .AnnotationAttributes ;
57
58
import org .springframework .core .annotation .AnnotationUtils ;
58
59
import org .springframework .core .convert .ConversionFailedException ;
@@ -759,44 +760,24 @@ else if (!Modifier.isPublic(method1.getModifiers())) {
759
760
ambiguousFallbackType , ambiguousFallbackMessageGenericType , matchesAnnotation , handlerMethod1 );
760
761
}
761
762
762
- }, new UniqueMethodFilter (targetClass ));
763
+ }, (( ReflectionUtils . MethodFilter ) this :: isHandlerMethod ). and ( new UniqueMethodFilter (targetClass ) ));
763
764
764
765
if (candidateMethods .isEmpty () && candidateMessageMethods .isEmpty () && fallbackMethods .isEmpty ()
765
766
&& fallbackMessageMethods .isEmpty ()) {
766
767
findSingleSpecificMethodOnInterfacesIfProxy (candidateMessageMethods , candidateMethods );
767
768
}
768
769
}
769
770
770
- @ Nullable
771
- private HandlerMethod obtainHandlerMethodIfAny (Method methodToProcess ) {
772
- HandlerMethod handlerMethodToUse = null ;
773
- if (isMethodEligible (methodToProcess )) {
774
- try {
775
- handlerMethodToUse = createHandlerMethod (
776
- AopUtils .selectInvocableMethod (methodToProcess , ClassUtils .getUserClass (this .targetObject )));
777
- }
778
- catch (Exception ex ) {
779
- LOGGER .debug (ex , "Method [" + methodToProcess + "] is not eligible for Message handling." );
780
- return null ;
781
- }
782
-
783
- if (AnnotationUtils .getAnnotation (methodToProcess , Default .class ) != null ) {
784
- Assert .state (this .defaultHandlerMethod == null ,
785
- () -> "Only one method can be @Default, but there are more for: " + this .targetObject );
786
- this .defaultHandlerMethod = handlerMethodToUse ;
787
- }
788
- }
789
-
790
- return handlerMethodToUse ;
791
- }
792
-
793
- private boolean isMethodEligible (Method methodToProcess ) {
794
- return !(methodToProcess .isBridge () || // NOSONAR boolean complexity
795
- isMethodDefinedOnObjectClass (methodToProcess ) ||
796
- methodToProcess .getDeclaringClass ().equals (Proxy .class ) ||
797
- (this .requiresReply && void .class .equals (methodToProcess .getReturnType ())) ||
798
- (this .methodName != null && !this .methodName .equals (methodToProcess .getName ())) ||
799
- (this .methodName == null && isPausableMethod (methodToProcess )));
771
+ private boolean isHandlerMethod (Method method ) {
772
+ Class <?> declaringClass = method .getDeclaringClass ();
773
+ return !(method .isSynthetic () ||
774
+ ReflectionUtils .isObjectMethod (method ) ||
775
+ AnnotatedElementUtils .isAnnotated (method , "groovy.transform.Generated" ) ||
776
+ declaringClass .getName ().equals ("groovy.lang.GroovyObject" ) ||
777
+ declaringClass .equals (Proxy .class ) ||
778
+ (this .requiresReply && void .class .equals (method .getReturnType ())) ||
779
+ (this .methodName != null && !this .methodName .equals (method .getName ())) ||
780
+ (this .methodName == null && isPausableMethod (method )));
800
781
}
801
782
802
783
private boolean isPausableMethod (Method pausableMethod ) {
@@ -811,6 +792,27 @@ private boolean isPausableMethod(Method pausableMethod) {
811
792
return pausable ;
812
793
}
813
794
795
+ @ Nullable
796
+ private HandlerMethod obtainHandlerMethodIfAny (Method methodToProcess ) {
797
+ HandlerMethod handlerMethodToUse ;
798
+ try {
799
+ handlerMethodToUse = createHandlerMethod (
800
+ AopUtils .selectInvocableMethod (methodToProcess , ClassUtils .getUserClass (this .targetObject )));
801
+ }
802
+ catch (Exception ex ) {
803
+ LOGGER .debug (ex , "Method [" + methodToProcess + "] is not eligible for Message handling." );
804
+ return null ;
805
+ }
806
+
807
+ if (AnnotationUtils .getAnnotation (methodToProcess , Default .class ) != null ) {
808
+ Assert .state (this .defaultHandlerMethod == null ,
809
+ () -> "Only one method can be @Default, but there are more for: " + this .targetObject );
810
+ this .defaultHandlerMethod = handlerMethodToUse ;
811
+ }
812
+
813
+ return handlerMethodToUse ;
814
+ }
815
+
814
816
private void populateHandlerMethod (Map <Class <?>, HandlerMethod > candidateMethods ,
815
817
Map <Class <?>, HandlerMethod > candidateMessageMethods , Map <Class <?>, HandlerMethod > fallbackMethods ,
816
818
Map <Class <?>, HandlerMethod > fallbackMessageMethods , AtomicReference <Class <?>> ambiguousFallbackType ,
@@ -1013,8 +1015,7 @@ private HandlerMethod findClosestMatch(Class<?> payloadType) {
1013
1015
1014
1016
private static boolean isMethodDefinedOnObjectClass (Method method ) {
1015
1017
return method != null && // NOSONAR
1016
- (method .getDeclaringClass ().equals (Object .class ) || ReflectionUtils .isEqualsMethod (method ) ||
1017
- ReflectionUtils .isHashCodeMethod (method ) || ReflectionUtils .isToStringMethod (method ) ||
1018
+ (ReflectionUtils .isObjectMethod (method ) ||
1018
1019
AopUtils .isFinalizeMethod (method ) || (method .getName ().equals ("clone" )
1019
1020
&& method .getParameterTypes ().length == 0 ));
1020
1021
}
0 commit comments