Skip to content

Commit 616f728

Browse files
committed
MethodIntrospector handles overriding bridge method correctly
Closes gh-30906
1 parent 161a717 commit 616f728

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ void replyWithPayload() {
517517
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
518518
TestEventListener listener = this.context.getBean(TestEventListener.class);
519519

520-
521520
this.eventCollector.assertNoEventReceived(listener);
522521
this.eventCollector.assertNoEventReceived(replyEventListener);
523522
this.context.publishEvent(event);
@@ -634,6 +633,17 @@ void orderedListeners() {
634633
assertThat(listener.order).contains("first", "second", "third");
635634
}
636635

636+
@Test
637+
void publicSubclassWithInheritedEventListener() {
638+
load(PublicSubclassWithInheritedEventListener.class);
639+
TestEventListener listener = this.context.getBean(PublicSubclassWithInheritedEventListener.class);
640+
641+
this.eventCollector.assertNoEventReceived(listener);
642+
this.context.publishEvent("test");
643+
this.eventCollector.assertEvent(listener, "test");
644+
this.eventCollector.assertTotalEventsCount(1);
645+
}
646+
637647
@Test @Disabled // SPR-15122
638648
void listenersReceiveEarlyEvents() {
639649
load(EventOnPostConstruct.class, OrderedTestListener.class);
@@ -646,7 +656,7 @@ void listenersReceiveEarlyEvents() {
646656
void missingListenerBeanIgnored() {
647657
load(MissingEventListener.class);
648658
context.getBean(UseMissingEventListener.class);
649-
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
659+
context.publishEvent(new TestEvent(this));
650660
}
651661

652662

@@ -753,7 +763,6 @@ static class ContextEventListener extends AbstractTestEventListener {
753763
public void handleContextEvent(ApplicationContextEvent event) {
754764
collectEvent(event);
755765
}
756-
757766
}
758767

759768

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

981990

982-
983991
@EventListener
984992
@Retention(RetentionPolicy.RUNTIME)
985993
public @interface ConditionalEvent {
@@ -1031,7 +1039,7 @@ public void handleRatio(Double ratio) {
10311039
}
10321040

10331041

1034-
@Configuration
1042+
@Component
10351043
static class OrderedTestListener extends TestEventListener {
10361044

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

10571065

1066+
@Component
1067+
public static class PublicSubclassWithInheritedEventListener extends TestEventListener {
1068+
}
1069+
1070+
10581071
static class EventOnPostConstruct {
10591072

10601073
@Autowired

spring-core/src/main/java/org/springframework/core/MethodIntrospector.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,8 @@ public static <T> Map<Method, T> selectMethods(Class<?> targetType, final Metada
7474
T result = metadataLookup.inspect(specificMethod);
7575
if (result != null) {
7676
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
77-
if (bridgedMethod == specificMethod || metadataLookup.inspect(bridgedMethod) == null) {
77+
if (bridgedMethod == specificMethod || bridgedMethod == method ||
78+
metadataLookup.inspect(bridgedMethod) == null) {
7879
methodMap.put(specificMethod, result);
7980
}
8081
}

0 commit comments

Comments
 (0)