Skip to content

MethodIntrospector.selectMethods(…) fails to find methods in case of special bridge method arrangement #30906

@odrotbohm

Description

@odrotbohm

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);
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions