Skip to content

Commit

Permalink
MethodIntrospector handles overriding bridge method correctly
Browse files Browse the repository at this point in the history
Closes gh-30906
  • Loading branch information
jhoeller committed Jul 18, 2023
1 parent 161a717 commit 616f728
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Expand Up @@ -517,7 +517,6 @@ void replyWithPayload() {
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
TestEventListener listener = this.context.getBean(TestEventListener.class);


this.eventCollector.assertNoEventReceived(listener);
this.eventCollector.assertNoEventReceived(replyEventListener);
this.context.publishEvent(event);
Expand Down Expand Up @@ -634,6 +633,17 @@ void orderedListeners() {
assertThat(listener.order).contains("first", "second", "third");
}

@Test
void publicSubclassWithInheritedEventListener() {
load(PublicSubclassWithInheritedEventListener.class);
TestEventListener listener = this.context.getBean(PublicSubclassWithInheritedEventListener.class);

this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent("test");
this.eventCollector.assertEvent(listener, "test");
this.eventCollector.assertTotalEventsCount(1);
}

@Test @Disabled // SPR-15122
void listenersReceiveEarlyEvents() {
load(EventOnPostConstruct.class, OrderedTestListener.class);
Expand All @@ -646,7 +656,7 @@ void listenersReceiveEarlyEvents() {
void missingListenerBeanIgnored() {
load(MissingEventListener.class);
context.getBean(UseMissingEventListener.class);
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
context.publishEvent(new TestEvent(this));
}


Expand Down Expand Up @@ -753,7 +763,6 @@ static class ContextEventListener extends AbstractTestEventListener {
public void handleContextEvent(ApplicationContextEvent event) {
collectEvent(event);
}

}


Expand Down Expand Up @@ -979,7 +988,6 @@ public void handleString(GenericEventPojo<String> value) {
}



@EventListener
@Retention(RetentionPolicy.RUNTIME)
public @interface ConditionalEvent {
Expand Down Expand Up @@ -1031,7 +1039,7 @@ public void handleRatio(Double ratio) {
}


@Configuration
@Component
static class OrderedTestListener extends TestEventListener {

public final List<String> order = new ArrayList<>();
Expand All @@ -1055,6 +1063,11 @@ public void handleSecond(String payload) {
}


@Component
public static class PublicSubclassWithInheritedEventListener extends TestEventListener {
}


static class EventOnPostConstruct {

@Autowired
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,7 +74,8 @@ public static <T> Map<Method, T> selectMethods(Class<?> targetType, final Metada
T result = metadataLookup.inspect(specificMethod);
if (result != null) {
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (bridgedMethod == specificMethod || metadataLookup.inspect(bridgedMethod) == null) {
if (bridgedMethod == specificMethod || bridgedMethod == method ||
metadataLookup.inspect(bridgedMethod) == null) {
methodMap.put(specificMethod, result);
}
}
Expand Down

0 comments on commit 616f728

Please sign in to comment.