Skip to content

Commit f657952

Browse files
committed
EventListenerMethodProcessor defensively handles unresolvable method signatures
Issue: SPR-14330
1 parent 9394616 commit f657952

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.core.annotation.AnnotatedElementUtils;
4343
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
4444
import org.springframework.util.Assert;
45+
import org.springframework.util.CollectionUtils;
4546

4647
/**
4748
* Register {@link EventListener} annotated method as individual {@link ApplicationListener}
@@ -125,14 +126,23 @@ protected List<EventListenerFactory> getEventListenerFactories() {
125126

126127
protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
127128
if (!this.nonAnnotatedClasses.contains(targetType)) {
128-
Map<Method, EventListener> annotatedMethods = MethodIntrospector.selectMethods(targetType,
129-
new MethodIntrospector.MetadataLookup<EventListener>() {
130-
@Override
131-
public EventListener inspect(Method method) {
132-
return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class);
133-
}
134-
});
135-
if (annotatedMethods.isEmpty()) {
129+
Map<Method, EventListener> annotatedMethods = null;
130+
try {
131+
annotatedMethods = MethodIntrospector.selectMethods(targetType,
132+
new MethodIntrospector.MetadataLookup<EventListener>() {
133+
@Override
134+
public EventListener inspect(Method method) {
135+
return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class);
136+
}
137+
});
138+
}
139+
catch (Throwable ex) {
140+
// An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
141+
if (logger.isDebugEnabled()) {
142+
logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
143+
}
144+
}
145+
if (CollectionUtils.isEmpty(annotatedMethods)) {
136146
this.nonAnnotatedClasses.add(targetType);
137147
if (logger.isTraceEnabled()) {
138148
logger.trace("No @EventListener annotations found on bean class: " + targetType);

0 commit comments

Comments
 (0)