52
52
import org .springframework .core .LocalVariableTableParameterNameDiscoverer ;
53
53
import org .springframework .core .MethodParameter ;
54
54
import org .springframework .core .ParameterNameDiscoverer ;
55
+ import org .springframework .core .annotation .AnnotatedElementUtils ;
55
56
import org .springframework .core .annotation .AnnotationAttributes ;
56
57
import org .springframework .core .annotation .AnnotationUtils ;
57
58
import org .springframework .core .convert .ConversionFailedException ;
@@ -785,44 +786,24 @@ else if (!Modifier.isPublic(method1.getModifiers())) {
785
786
ambiguousFallbackType , ambiguousFallbackMessageGenericType , matchesAnnotation , handlerMethod1 );
786
787
}
787
788
788
- }, new UniqueMethodFilter (targetClass ));
789
+ }, (( ReflectionUtils . MethodFilter ) this :: isHandlerMethod ). and ( new UniqueMethodFilter (targetClass ) ));
789
790
790
791
if (candidateMethods .isEmpty () && candidateMessageMethods .isEmpty () && fallbackMethods .isEmpty ()
791
792
&& fallbackMessageMethods .isEmpty ()) {
792
793
findSingleSpecificMethodOnInterfacesIfProxy (candidateMessageMethods , candidateMethods );
793
794
}
794
795
}
795
796
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 )));
826
807
}
827
808
828
809
private boolean isPausableMethod (Method pausableMethod ) {
@@ -837,6 +818,27 @@ private boolean isPausableMethod(Method pausableMethod) {
837
818
return pausable ;
838
819
}
839
820
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
+
840
842
private void populateHandlerMethod (Map <Class <?>, HandlerMethod > candidateMethods ,
841
843
Map <Class <?>, HandlerMethod > candidateMessageMethods , Map <Class <?>, HandlerMethod > fallbackMethods ,
842
844
Map <Class <?>, HandlerMethod > fallbackMessageMethods , AtomicReference <Class <?>> ambiguousFallbackType ,
@@ -1041,8 +1043,7 @@ private HandlerMethod findClosestMatch(Class<?> payloadType) {
1041
1043
1042
1044
private static boolean isMethodDefinedOnObjectClass (Method method ) {
1043
1045
return method != null && // NOSONAR
1044
- (method .getDeclaringClass ().equals (Object .class ) || ReflectionUtils .isEqualsMethod (method ) ||
1045
- ReflectionUtils .isHashCodeMethod (method ) || ReflectionUtils .isToStringMethod (method ) ||
1046
+ (ReflectionUtils .isObjectMethod (method ) ||
1046
1047
AopUtils .isFinalizeMethod (method ) || (method .getName ().equals ("clone" )
1047
1048
&& method .getParameterTypes ().length == 0 ));
1048
1049
}
0 commit comments