Skip to content

Commit da2c8fc

Browse files
committed
Add defensive check for RabbitProperties to prevent NPE
Before this commit, RabbitProperties cannot be copied when addresses is null. Signed-off-by: Yanming Zhou <[email protected]>
1 parent 6957557 commit da2c8fc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ public void setAddresses(List<String> addresses) {
233233
}
234234

235235
private List<Address> parseAddresses(List<String> addresses) {
236+
if (addresses == null) {
237+
return null;
238+
}
236239
List<Address> parsedAddresses = new ArrayList<>();
237240
for (String address : addresses) {
238241
parsedAddresses.add(new Address(address, Optional.ofNullable(getSsl().getEnabled()).orElse(false)));

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
2626
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
2727
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
28+
import org.springframework.beans.BeanUtils;
2829
import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException;
2930

3031
import static org.assertj.core.api.Assertions.assertThat;
@@ -381,4 +382,11 @@ void hostPropertyMustBeSingleHost() {
381382
.withMessageContaining("spring.rabbitmq.host");
382383
}
383384

385+
@Test
386+
void isSafeForCopyProperties() {
387+
this.properties.setHost("my-rmq-host.net");
388+
RabbitProperties target = new RabbitProperties();
389+
BeanUtils.copyProperties(this.properties, target);
390+
}
391+
384392
}

0 commit comments

Comments
 (0)