Skip to content

Commit df99ad1

Browse files
committed
Merge branch '2.7.x'
Closes gh-31184
2 parents 97197f8 + 194e9f0 commit df99ad1

File tree

2 files changed

+24
-3
lines changed
  • spring-boot-project/spring-boot/src
    • main/java/org/springframework/boot/context/properties/bind
    • test/java/org/springframework/boot/context/properties/bind

2 files changed

+24
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public class Binder {
7272
* @param sources the sources used for binding
7373
*/
7474
public Binder(ConfigurationPropertySource... sources) {
75-
this(Arrays.asList(sources), null, null, null);
75+
this((sources != null) ? Arrays.asList(sources) : null, null, null, null);
7676
}
7777

7878
/**
@@ -182,6 +182,9 @@ public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolve
182182
List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer,
183183
BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) {
184184
Assert.notNull(sources, "Sources must not be null");
185+
for (ConfigurationPropertySource source : sources) {
186+
Assert.notNull(source, "Sources must not contain null elements");
187+
}
185188
this.sources = sources;
186189
this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE;
187190
this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,29 @@ class BinderTests {
6969
private Binder binder = new Binder(this.sources);
7070

7171
@Test
72-
void createWhenSourcesIsNullShouldThrowException() {
72+
void createWhenSourcesIsNullArrayShouldThrowException() {
73+
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((ConfigurationPropertySource[]) null))
74+
.withMessageContaining("Sources must not be null");
75+
}
76+
77+
@Test
78+
void creatWhenSourcesIsNullIterableShouldThrowException() {
7379
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((Iterable<ConfigurationPropertySource>) null))
7480
.withMessageContaining("Sources must not be null");
7581
}
7682

83+
@Test
84+
void createWhenArraySourcesContainsNullElementShouldThrowException() {
85+
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(new ConfigurationPropertySource[] { null }))
86+
.withMessageContaining("Sources must not contain null elements");
87+
}
88+
89+
@Test
90+
void createWhenIterableSourcesContainsNullElementShouldThrowException() {
91+
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(Collections.singletonList(null)))
92+
.withMessageContaining("Sources must not contain null elements");
93+
}
94+
7795
@Test
7896
void bindWhenNameIsNullShouldThrowException() {
7997
assertThatIllegalArgumentException().isThrownBy(() -> this.binder.bind((ConfigurationPropertyName) null,

0 commit comments

Comments
 (0)