Skip to content

Commit 0ed7f9a

Browse files
committed
SimpleApplicationEventMulticaster leniently handles ClassCastException
Issue: SPR-14109 (cherry picked from commit 13f889e)
1 parent 02a6f31 commit 0ed7f9a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -18,6 +18,8 @@
1818

1919
import java.util.concurrent.Executor;
2020

21+
import org.apache.commons.logging.LogFactory;
22+
2123
import org.springframework.beans.factory.BeanFactory;
2224
import org.springframework.context.ApplicationEvent;
2325
import org.springframework.context.ApplicationListener;
@@ -160,7 +162,13 @@ protected void invokeListener(ApplicationListener listener, ApplicationEvent eve
160162
}
161163
}
162164
else {
163-
listener.onApplicationEvent(event);
165+
try {
166+
listener.onApplicationEvent(event);
167+
}
168+
catch (ClassCastException ex) {
169+
// Possibly a lambda-defined listener which we could not resolve the generic event type for
170+
LogFactory.getLog(getClass()).debug("Non-matching event type for listener: " + listener, ex);
171+
}
164172
}
165173
}
166174

0 commit comments

Comments
 (0)