diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java index 31983009e5..0b47cff04e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java @@ -182,7 +182,9 @@ public class Binder { List conversionServices, Consumer propertyEditorInitializer, BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) { Assert.notNull(sources, "Sources must not be null"); - sources.forEach((source) -> Assert.notNull(source, "Sources cannot contain null values")); + for (ConfigurationPropertySource source : sources) { + Assert.notNull(source, "Sources must not contain null elements"); + } this.sources = sources; this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE; this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java index 360e567ad6..388348bf9a 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java @@ -70,19 +70,27 @@ class BinderTests { private Binder binder = new Binder(this.sources); @Test - void createWhenSourcesIsNullShouldThrowException() { + void createWhenSourcesIsNullArrayShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new Binder((ConfigurationPropertySource[]) null)) .withMessageContaining("Sources must not be null"); + } + + @Test + void creatWhenSourcesIsNullIterableShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new Binder((Iterable) null)) .withMessageContaining("Sources must not be null"); } @Test - void createWhenSourcesContainNullValuesShouldThrowException() { + void createWhenArraySourcesContainsNullElementShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new Binder(new ConfigurationPropertySource[] { null })) - .withMessageContaining("Sources cannot contain null values"); + .withMessageContaining("Sources must not contain null elements"); + } + + @Test + void createWhenIterableSourcesContainsNullElementShouldThrowException() { assertThatIllegalArgumentException().isThrownBy(() -> new Binder(Collections.singletonList(null))) - .withMessageContaining("Sources cannot contain null values"); + .withMessageContaining("Sources must not contain null elements"); } @Test