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.
Comment on lines +131 to +132

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's either:

  1. not ref the issue in the test case
  2. actually link to the issue rather than using a shorthand

+1 on having the test case though

@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