-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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:
- Support Mutable Messages with optional ID and timestamp headers [SPR-11468] #16094 Support Mutable Messages with optional ID and timestamp headers