In the case of an inheritance arrangement between types MethodIntrospector.selectMethods(…) might fail to detect methods on super classes as the bridge methods in the subclass introduced by the compiler. For this arrangement:
class SampleTest {
@Test
void testName() {
Map<Method, EventListener> selectMethods = MethodIntrospector.selectMethods(B.class,
(MethodIntrospector.MetadataLookup<EventListener>) method -> AnnotatedElementUtils
.findMergedAnnotation(method, EventListener.class));
assertThat(selectMethods).hasSize(1);
}
static abstract class A {
@EventListener
public void externalize(Object event) {
}
}
public static class B extends A {
}
}
The inspection of A.externalize(…) will detect a bridge method B.externalize(…), which lets the following guard clause kick in and prevent A.externalize(…) from being selected:
if (bridgedMethod == specificMethod || metadataLookup.inspect(bridgedMethod) == null) {
methodMap.put(specificMethod, result);
}
In the case of an inheritance arrangement between types
MethodIntrospector.selectMethods(…)might fail to detect methods on super classes as the bridge methods in the subclass introduced by the compiler. For this arrangement:The inspection of
A.externalize(…)will detect a bridge methodB.externalize(…), which lets the following guard clause kick in and preventA.externalize(…)from being selected: