Skip to content

Commit 04dcfdb

Browse files
committed
GH-3246: Fix NPEs for AMQP properties conversion
Fixes: #3246 The received message might come not from Spring AMQP source, therefore it might not have `priority` and `content-type` set. * Fix `DefaultMessagePropertiesConverter` checking for the nulls in the `priority` and `content-type` * Remove redundant null check for `priority` in the `MessageBuilderSupport`
1 parent b42da81 commit 04dcfdb

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

spring-amqp/src/main/java/org/springframework/amqp/core/MessageBuilderSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* @param <T> The message builder type.
3232
*
3333
* @author Gary Russell
34+
* @author Artem Bilan
3435
*
3536
* @since 1.3
3637
*
@@ -267,8 +268,7 @@ public MessageBuilderSupport<T> setExpirationIfAbsent(String expiration) {
267268
}
268269

269270
public MessageBuilderSupport<T> setPriorityIfAbsentOrDefault(Integer priority) {
270-
if (this.properties.getPriority() == null
271-
|| MessageProperties.DEFAULT_PRIORITY.equals(this.properties.getPriority())) {
271+
if (MessageProperties.DEFAULT_PRIORITY.equals(this.properties.getPriority())) {
272272
this.properties.setPriority(priority);
273273
}
274274
return this;

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/DefaultMessagePropertiesConverter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ else if (MessageProperties.RETRY_COUNT.equals(key)) {
127127
}
128128
target.setDeliveryMode(null);
129129
target.setExpiration(source.getExpiration());
130-
target.setPriority(source.getPriority());
131-
target.setContentType(source.getContentType());
130+
Integer priority = source.getPriority();
131+
if (priority != null) {
132+
target.setPriority(priority);
133+
}
134+
String contentType = source.getContentType();
135+
if (contentType != null) {
136+
target.setContentType(contentType);
137+
}
132138
target.setContentEncoding(source.getContentEncoding());
133139
String correlationId = source.getCorrelationId();
134140
if (StringUtils.hasText(correlationId)) {

0 commit comments

Comments
 (0)