Skip to content

Commit 0655d73

Browse files
committed
SimpleApplicationEventMulticaster defensively handles ClassCastException without message
Issue: SPR-15145 (cherry picked from commit 153fd82)
1 parent 24ebd15 commit 0655d73

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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,7 @@
1818

1919
import java.util.concurrent.Executor;
2020

21+
import org.apache.commons.logging.Log;
2122
import org.apache.commons.logging.LogFactory;
2223

2324
import org.springframework.beans.factory.BeanFactory;
@@ -166,9 +167,13 @@ protected void invokeListener(ApplicationListener listener, ApplicationEvent eve
166167
listener.onApplicationEvent(event);
167168
}
168169
catch (ClassCastException ex) {
169-
if (ex.getMessage().startsWith(event.getClass().getName())) {
170+
String msg = ex.getMessage();
171+
if (msg != null && msg.startsWith(event.getClass().getName())) {
170172
// Possibly a lambda-defined listener which we could not resolve the generic event type for
171-
LogFactory.getLog(getClass()).debug("Non-matching event type for listener: " + listener, ex);
173+
Log logger = LogFactory.getLog(getClass());
174+
if (logger.isDebugEnabled()) {
175+
logger.debug("Non-matching event type for listener: " + listener, ex);
176+
}
172177
}
173178
else {
174179
throw ex;

0 commit comments

Comments
 (0)