Description
Mariusz Luciow opened SPR-15145 and commented
SimpleApplicationEventMulticaster in this commit driven by #19412 changed the ClassCastException catch logic to:
catch (ClassCastException ex) {
if (ex.getMessage().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);
} else {
throw ex;
}
}
Note that if ex.getMessage() returns NULL whole method will throw NPE.
To speed up execution of methods that frequently throw exceptions, the C2 compiler generates code that uses a pre-built exception (pre-built at compile time). The pre-built exception does not contain neither a stack trace nor a message detailing the exception.
This means that after some time the compiler can replace normal ClassCastException with empty one, without message nor stack trace.
More detailed explanation of this behaviour can be found here:
There should be a check in place to ensure that message is not null.
Affects: 4.3.5
Reference URL: 13001b9#diff-2434dcbaad29ced6a104bb6523c4f67e
Issue Links:
- SimpleApplicationEventMulticaster should not generally suppress ClassCastException [SPR-14846] #19412 SimpleApplicationEventMulticaster should not generally suppress ClassCastException
- SimpleApplicationEventMulticaster does not deal with lambda-defined listeners when ErrorHandler is set [SPR-15838] #20393 SimpleApplicationEventMulticaster does not deal with lambda-defined listeners when ErrorHandler is set
- Lambda error detection might not work on JDK 9 [SPR-16435] #20981 Lambda error detection might not work on JDK 9
- Classification of ClassCastExceptions doesn't work in JDK 11 (OpenJDK) [SPR-17093] #21630 Classification of ClassCastExceptions doesn't work in JDK 11 (OpenJDK)