Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in AbstractMessageSendingTemplate when headers are null and converter returns null [SPR-11653] #16276

Closed
spring-projects-issues opened this issue Apr 3, 2014 · 1 comment
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 3, 2014

Anders Schuller opened SPR-11653 and commented

When AbstractMessageSendingTemplate.convertAndSend is called with null headers and a payload that the converter cannot convert (i.e. converter.toMessage also returns null), the code attempts to throw a MessageConversionException but a NullPointerException occurs instead as the exception message attempts to get the content type from the null headers.

The relevant bit of code from AbstractMessageSendingTemplate:

MessageHeaders messageHeaders = (headers != null) ? new MessageHeaders(headers) : null;
Message<?> message = this.converter.toMessage(payload, messageHeaders);

if (message == null) {
	String payloadType = (payload != null) ? payload.getClass().getName() : null;
	throw new MessageConversionException("Unable to convert payload type '"
			+ payloadType + "', Content-Type=" + messageHeaders.get(MessageHeaders.CONTENT_TYPE)
			+ ", converter=" + this.converter, null);
}

This bit of code was added with this commit, which I believe means AbstractMessagingTemplate.convertSendAndReceive is also affected. The fix is probably as easy as making the content type a separate variable where the headers can be null-checked, similar to how payloadType is declared.


Affects: 4.0.2, 4.0.3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Apr 17, 2014

Juergen Hoeller commented

This got fixed along with the wider-scale #16094. I'll backport the content type extraction part to 4.0.4.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants