-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug
Milestone
Description
Johannes Scharf opened SPR-10945 and commented
AbstractApplicationEventMulticaster
throws a NullPointerException
at line 131 if the ApplicationEvent's
source is null
:
protected Collection<ApplicationListener> getApplicationListeners(ApplicationEvent event) {
Class<? extends ApplicationEvent> eventType = event.getClass();
Class sourceType = event.getSource().getClass(); // NPE here if source is null
ListenerCacheKey cacheKey = new ListenerCacheKey(eventType, sourceType);
ListenerRetriever retriever = this.retrieverCache.get(cacheKey);
if (retriever != null) {
return retriever.getApplicationListeners();
}
// Rest omitted
The Event's source is null
because we serialize our objects to XML by using XStream and publishing them later asynchronously by a job. Unfortunately source
is declared transient
in EventObject
(the superclass of ApplicationEvent
) and hence not serialized by XStream. Therefore after deserialization from XML source
is null
.
Although we could work around this by setting source
(it has modifier protected
) again after deserialization AbstractApplicationEventMulticaster
should not blow up and handle null
source of events more robust.
Affects: 3.2.3
Sub-tasks:
- Backport: AbstractApplicationEventMulticaster throws NPE when ApplicationEvent's source is null [SPR-11012] #15640 Backport: AbstractApplicationEventMulticaster throws NPE when ApplicationEvent's source is null
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug