2020import java .util .List ;
2121import java .util .Map ;
2222import java .util .Objects ;
23+ import java .util .Random ;
2324import java .util .function .Function ;
2425
25- import org .springframework .boot .env .RandomValuePropertySource ;
2626import org .springframework .boot .origin .Origin ;
2727import org .springframework .boot .origin .PropertySourceOrigin ;
2828import org .springframework .core .env .EnumerablePropertySource ;
@@ -61,24 +61,24 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
6161
6262 private final PropertyMapper mapper ;
6363
64- private final Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOfMethod ;
64+ private final Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOf ;
6565
6666 /**
6767 * Create a new {@link SpringConfigurationPropertySource} implementation.
6868 * @param propertySource the source property source
6969 * @param mapper the property mapper
70- * @param containsDescendantOfMethod function used to implement
70+ * @param containsDescendantOf function used to implement
7171 * {@link #containsDescendantOf(ConfigurationPropertyName)} (may be {@code null})
7272 */
7373 SpringConfigurationPropertySource (PropertySource <?> propertySource ,
7474 PropertyMapper mapper ,
75- Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOfMethod ) {
75+ Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOf ) {
7676 Assert .notNull (propertySource , "PropertySource must not be null" );
7777 Assert .notNull (mapper , "Mapper must not be null" );
7878 this .propertySource = propertySource ;
7979 this .mapper = new ExceptionSwallowingPropertyMapper (mapper );
80- this .containsDescendantOfMethod = (containsDescendantOfMethod != null
81- ? containsDescendantOfMethod : (n ) -> ConfigurationPropertyState .UNKNOWN );
80+ this .containsDescendantOf = (containsDescendantOf != null ? containsDescendantOf
81+ : (n ) -> ConfigurationPropertyState .UNKNOWN );
8282 }
8383
8484 @ Override
@@ -91,7 +91,7 @@ public ConfigurationProperty getConfigurationProperty(
9191 @ Override
9292 public ConfigurationPropertyState containsDescendantOf (
9393 ConfigurationPropertyName name ) {
94- return this .containsDescendantOfMethod .apply (name );
94+ return this .containsDescendantOf .apply (name );
9595 }
9696
9797 @ Override
@@ -146,7 +146,7 @@ public static SpringConfigurationPropertySource from(PropertySource<?> source) {
146146 (EnumerablePropertySource <?>) source , mapper );
147147 }
148148 return new SpringConfigurationPropertySource (source , mapper ,
149- getContainsDescendantOfMethod (source ));
149+ getContainsDescendantOfForSource (source ));
150150 }
151151
152152 private static PropertyMapper getPropertyMapper (PropertySource <?> source ) {
@@ -178,16 +178,22 @@ private static PropertySource<?> getRootSource(PropertySource<?> source) {
178178 return source ;
179179 }
180180
181- private static Function <ConfigurationPropertyName , ConfigurationPropertyState > getContainsDescendantOfMethod (
181+ private static Function <ConfigurationPropertyName , ConfigurationPropertyState > getContainsDescendantOfForSource (
182182 PropertySource <?> source ) {
183- if (source instanceof RandomValuePropertySource ) {
184- return (name ) -> (name .isAncestorOf (RANDOM ) || name .equals (RANDOM )
185- ? ConfigurationPropertyState .PRESENT
186- : ConfigurationPropertyState .ABSENT );
183+ if (source .getSource () instanceof Random ) {
184+ return SpringConfigurationPropertySource ::containsDescendantOfForRandom ;
187185 }
188186 return null ;
189187 }
190188
189+ private static ConfigurationPropertyState containsDescendantOfForRandom (
190+ ConfigurationPropertyName name ) {
191+ if (name .isAncestorOf (RANDOM ) || name .equals (RANDOM )) {
192+ return ConfigurationPropertyState .PRESENT ;
193+ }
194+ return ConfigurationPropertyState .ABSENT ;
195+ }
196+
191197 /**
192198 * {@link PropertyMapper} that swallows exceptions when the mapping fails.
193199 */
0 commit comments