diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java index 0a0592a530..ae495ee748 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java @@ -20,9 +20,9 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Random; import java.util.function.Function; -import org.springframework.boot.env.RandomValuePropertySource; import org.springframework.boot.origin.Origin; import org.springframework.boot.origin.PropertySourceOrigin; import org.springframework.core.env.EnumerablePropertySource; @@ -61,24 +61,24 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { private final PropertyMapper mapper; - private final Function containsDescendantOfMethod; + private final Function containsDescendantOf; /** * Create a new {@link SpringConfigurationPropertySource} implementation. * @param propertySource the source property source * @param mapper the property mapper - * @param containsDescendantOfMethod function used to implement + * @param containsDescendantOf function used to implement * {@link #containsDescendantOf(ConfigurationPropertyName)} (may be {@code null}) */ SpringConfigurationPropertySource(PropertySource propertySource, PropertyMapper mapper, - Function containsDescendantOfMethod) { + Function containsDescendantOf) { Assert.notNull(propertySource, "PropertySource must not be null"); Assert.notNull(mapper, "Mapper must not be null"); this.propertySource = propertySource; this.mapper = new ExceptionSwallowingPropertyMapper(mapper); - this.containsDescendantOfMethod = (containsDescendantOfMethod != null - ? containsDescendantOfMethod : (n) -> ConfigurationPropertyState.UNKNOWN); + this.containsDescendantOf = (containsDescendantOf != null ? containsDescendantOf + : (n) -> ConfigurationPropertyState.UNKNOWN); } @Override @@ -91,7 +91,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { @Override public ConfigurationPropertyState containsDescendantOf( ConfigurationPropertyName name) { - return this.containsDescendantOfMethod.apply(name); + return this.containsDescendantOf.apply(name); } @Override @@ -146,7 +146,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { (EnumerablePropertySource) source, mapper); } return new SpringConfigurationPropertySource(source, mapper, - getContainsDescendantOfMethod(source)); + getContainsDescendantOfForSource(source)); } private static PropertyMapper getPropertyMapper(PropertySource source) { @@ -178,16 +178,22 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource { return source; } - private static Function getContainsDescendantOfMethod( + private static Function getContainsDescendantOfForSource( PropertySource source) { - if (source instanceof RandomValuePropertySource) { - return (name) -> (name.isAncestorOf(RANDOM) || name.equals(RANDOM) - ? ConfigurationPropertyState.PRESENT - : ConfigurationPropertyState.ABSENT); + if (source.getSource() instanceof Random) { + return SpringConfigurationPropertySource::containsDescendantOfForRandom; } return null; } + private static ConfigurationPropertyState containsDescendantOfForRandom( + ConfigurationPropertyName name) { + if (name.isAncestorOf(RANDOM) || name.equals(RANDOM)) { + return ConfigurationPropertyState.PRESENT; + } + return ConfigurationPropertyState.ABSENT; + } + /** * {@link PropertyMapper} that swallows exceptions when the mapping fails. */