Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
odrotbohm opened this issue Jul 18, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@odrotbohm
Copy link
Member

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);
}
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jul 18, 2023
@jhoeller jhoeller self-assigned this Jul 18, 2023
@jhoeller jhoeller added this to the 6.0.12 milestone Jul 18, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x labels Jul 18, 2023
jhoeller added a commit that referenced this issue Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants