Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class MessageBuilderMessageWriter
private Map<String, Object> headers = new HashMap<>();

public MessageBuilderMessageWriter(Map<String, Object> headers) {
this.headers.putAll(headers);
if (headers != null) {
this.headers.putAll(headers);
}
}

public MessageBuilderMessageWriter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,19 @@ void fromNonCloudEvent() {
assertThat(converter.toMessage(new byte[0], new MessageHeaders(Collections.emptyMap()))).isNull();
}

// gh-689: toMessage should not throw NPE when the caller provides no headers,
// e.g. RabbitMessagingTemplate#convertAndSend(String, Object) passes null.
@Test
void fromCloudEventWithNullHeaders() {
CloudEvent attributes = CloudEventBuilder.v1().withId("A234-1234-1234")
.withSource(URI.create("https://spring.io/")).withType("org.springframework")
.withData("hello".getBytes(StandardCharsets.UTF_8)).build();
Message<?> message = converter.toMessage(attributes, null);
Map<String, ?> headers = message.getHeaders();
assertThat(headers.get("ce-id")).isEqualTo("A234-1234-1234");
assertThat(headers.get("ce-specversion")).isEqualTo("1.0");
assertThat(headers.get("ce-source")).isEqualTo("https://spring.io/");
assertThat(headers.get("ce-type")).isEqualTo("org.springframework");
}

}
Loading