From 153fd82946c350a0c42be2dbd13774d5ee9ffc0c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 16 Jan 2017 15:35:18 +0100 Subject: [PATCH] SimpleApplicationEventMulticaster defensively handles ClassCastException without message Issue: SPR-15145 --- .../event/SimpleApplicationEventMulticaster.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java index 95c8886a74..9fc78676c6 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -18,6 +18,7 @@ package org.springframework.context.event; import java.util.concurrent.Executor; +import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.BeanFactory; @@ -166,9 +167,13 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM listener.onApplicationEvent(event); } catch (ClassCastException ex) { - if (ex.getMessage().startsWith(event.getClass().getName())) { + String msg = ex.getMessage(); + if (msg != null && msg.startsWith(event.getClass().getName())) { // Possibly a lambda-defined listener which we could not resolve the generic event type for - LogFactory.getLog(getClass()).debug("Non-matching event type for listener: " + listener, ex); + Log logger = LogFactory.getLog(getClass()); + if (logger.isDebugEnabled()) { + logger.debug("Non-matching event type for listener: " + listener, ex); + } } else { throw ex;