Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-31183
  • Loading branch information
wilkinsona committed May 27, 2022
2 parents 137318a + 88974b5 commit 194e9f0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -72,7 +72,7 @@ public class Binder {
* @param sources the sources used for binding
*/
public Binder(ConfigurationPropertySource... sources) {
this(Arrays.asList(sources), null, null, null);
this((sources != null) ? Arrays.asList(sources) : null, null, null, null);
}

/**
Expand Down Expand Up @@ -182,6 +182,9 @@ public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolve
List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer,
BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) {
Assert.notNull(sources, "Sources must not be null");
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);
Expand Down
Expand Up @@ -70,11 +70,29 @@ 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<ConfigurationPropertySource>) null))
.withMessageContaining("Sources must not be null");
}

@Test
void createWhenArraySourcesContainsNullElementShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(new ConfigurationPropertySource[] { null }))
.withMessageContaining("Sources must not contain null elements");
}

@Test
void createWhenIterableSourcesContainsNullElementShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(Collections.singletonList(null)))
.withMessageContaining("Sources must not contain null elements");
}

@Test
void bindWhenNameIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.binder.bind((ConfigurationPropertyName) null,
Expand Down

0 comments on commit 194e9f0

Please sign in to comment.