Skip to content

AbstractApplicationEventMulticaster throws NPE when ApplicationEvent's source is null [SPR-10945] #15573

@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits b0ff834, 1ea7f74

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions