Protect against NPE with Option.IGNORE_IMPORTS
Update `ConfigDataEnvironmentContributor` to deal with the fact that the `properties` instance can be `null`. Fixes gh-25029
This commit is contained in:
parent
7f32fa6723
commit
0fcc52ccaf
|
@ -223,7 +223,7 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
|
|||
ConfigDataEnvironmentContributor withBoundProperties(Binder binder) {
|
||||
UseLegacyConfigProcessingException.throwIfRequested(binder);
|
||||
ConfigDataProperties properties = ConfigDataProperties.get(binder);
|
||||
if (this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
|
||||
if (properties != null && this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
|
||||
properties = properties.withoutImports();
|
||||
}
|
||||
return new ConfigDataEnvironmentContributor(Kind.BOUND_IMPORT, this.location, this.resource,
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.stream.Stream;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.config.ConfigData.Option;
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentContributor.ImportPhase;
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
|
@ -334,6 +335,17 @@ class ConfigDataEnvironmentContributorTests {
|
|||
() -> createBoundContributor(null, new ConfigData(Collections.singleton(propertySource)), 0));
|
||||
}
|
||||
|
||||
@Test // gh-25029
|
||||
void withBoundPropertiesWhenIgnoringImportsAndNothingBound() {
|
||||
TestResource resource = new TestResource("a");
|
||||
ConfigData configData = new ConfigData(Collections.singleton(new MockPropertySource()), Option.IGNORE_IMPORTS);
|
||||
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofUnboundImport(TEST_LOCATION,
|
||||
resource, false, configData, 0);
|
||||
Binder binder = new Binder(contributor.getConfigurationPropertySource());
|
||||
ConfigDataEnvironmentContributor bound = contributor.withBoundProperties(binder);
|
||||
assertThat(bound).isNotNull();
|
||||
}
|
||||
|
||||
private ConfigDataEnvironmentContributor createBoundContributor(String location) {
|
||||
return createBoundContributor(new TestResource(location),
|
||||
new ConfigData(Collections.singleton(new MockPropertySource())), 0);
|
||||
|
|
Loading…
Reference in New Issue