Skip to content

SimpleApplicationEventMulticaster should not rely on ClassCastException having a message [SPR-15145] #19711

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 976d32f, 153fd82, 64d4afa, 0655d73

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions