Removing the possibility of null propertysources being returned in the locator
This commit is contained in:
@@ -99,7 +99,7 @@ public class PropertySourceBootstrapConfiguration implements
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
for (PropertySourceLocator locator : this.propertySourceLocators) {
|
||||
Collection<PropertySource<?>> source = locator.locateCollection(environment);
|
||||
if (source == null) {
|
||||
if (source == null || source.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
List sourceList = new ArrayList<>();
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.bootstrap.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
@@ -43,8 +45,19 @@ public interface PropertySourceLocator {
|
||||
|
||||
default Collection<PropertySource<?>> locateCollection(Environment environment) {
|
||||
PropertySource propertySource = locate(environment);
|
||||
if (propertySource == null) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
if (CompositePropertySource.class.isInstance(propertySource)) {
|
||||
return ((CompositePropertySource) propertySource).getPropertySources();
|
||||
Collection<PropertySource<?>> sources = ((CompositePropertySource) propertySource)
|
||||
.getPropertySources();
|
||||
List<PropertySource<?>> filteredSources = new ArrayList<>();
|
||||
for (PropertySource p : sources) {
|
||||
if (p != null) {
|
||||
filteredSources.add(p);
|
||||
}
|
||||
}
|
||||
return filteredSources;
|
||||
}
|
||||
else {
|
||||
return (List) Arrays.asList(propertySource);
|
||||
|
||||
Reference in New Issue
Block a user