Skip to content

Binder(ConfigurationPropertySource... sources) does not assert that sources contains only non-null elements #30878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,7 @@ public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolve
List<ConversionService> conversionServices, Consumer<PropertyEditorRegistry> propertyEditorInitializer,
BindHandler defaultBindHandler, BindConstructorProvider constructorProvider) {
Assert.notNull(sources, "Sources must not be null");
sources.forEach((source) -> Assert.notNull(source, "Sources cannot contain null values"));
this.sources = sources;
this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE;
this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ class BinderTests {

@Test
void createWhenSourcesIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((ConfigurationPropertySource[]) null))
.withMessageContaining("Sources must not be null");
assertThatIllegalArgumentException().isThrownBy(() -> new Binder((Iterable<ConfigurationPropertySource>) null))
.withMessageContaining("Sources must not be null");
}

@Test
void createWhenSourcesContainNullValuesShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(new ConfigurationPropertySource[] { null }))
.withMessageContaining("Sources cannot contain null values");
assertThatIllegalArgumentException().isThrownBy(() -> new Binder(Collections.singletonList(null)))
.withMessageContaining("Sources cannot contain null values");
}

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