fix: handle null MessageHeaders in MessageBuilderMessageWriter (#689)#747
Open
prashantdotnaagar wants to merge 1 commit into
Open
fix: handle null MessageHeaders in MessageBuilderMessageWriter (#689)#747prashantdotnaagar wants to merge 1 commit into
prashantdotnaagar wants to merge 1 commit into
Conversation
Calling CloudEventMessageConverter.toMessage() with null MessageHeaders (as done by RabbitMessagingTemplate#convertAndSend) caused a NullPointerException in MessageBuilderMessageWriter.putAll(null). Added a null-guard in the constructor so null headers are treated as empty, preventing the NPE. Also adds regression test fromCloudEventWithNullHeaders. Closes cloudevents#689 Signed-off-by: Prashant nagar <prashantnaagar60@gmail.com>
prashantdotnaagar
force-pushed
the
fix/689-converter-null-headers
branch
from
July 18, 2026 11:00
7b5b757 to
8935f21
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
NullPointerExceptionthat occurs whenCloudEventMessageConverter.toMessage()is called withnullMessageHeaders— a scenario that happens when usingRabbitMessagingTemplate#convertAndSend(String, Object)(and similar Spring messaging templates that don't supply headers).Root Cause
CloudEventMessageConverter.toMessage()passes theheadersargument directly tonew MessageBuilderMessageWriter(headers). Inside the constructor,this.headers.putAll(headers)was called unconditionally, throwing an NPE whenheadersisnull.Fix
Added a null-guard in the
MessageBuilderMessageWriter(Map<String, Object> headers)constructor so that anullinput is treated as an empty map, while CloudEvent attributes are still written correctly.Test
Added regression test
fromCloudEventWithNullHeaderstoCloudEventMessageConverterTeststhat callsconverter.toMessage(event, null)and asserts the returned message contains the correct CloudEvent headers.All 9 tests in
CloudEventMessageConverterTestspass.Closes #689