20
20
import java .util .List ;
21
21
import java .util .Map ;
22
22
import java .util .Objects ;
23
+ import java .util .Random ;
23
24
import java .util .function .Function ;
24
25
25
- import org .springframework .boot .env .RandomValuePropertySource ;
26
26
import org .springframework .boot .origin .Origin ;
27
27
import org .springframework .boot .origin .PropertySourceOrigin ;
28
28
import org .springframework .core .env .EnumerablePropertySource ;
@@ -61,24 +61,24 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
61
61
62
62
private final PropertyMapper mapper ;
63
63
64
- private final Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOfMethod ;
64
+ private final Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOf ;
65
65
66
66
/**
67
67
* Create a new {@link SpringConfigurationPropertySource} implementation.
68
68
* @param propertySource the source property source
69
69
* @param mapper the property mapper
70
- * @param containsDescendantOfMethod function used to implement
70
+ * @param containsDescendantOf function used to implement
71
71
* {@link #containsDescendantOf(ConfigurationPropertyName)} (may be {@code null})
72
72
*/
73
73
SpringConfigurationPropertySource (PropertySource <?> propertySource ,
74
74
PropertyMapper mapper ,
75
- Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOfMethod ) {
75
+ Function <ConfigurationPropertyName , ConfigurationPropertyState > containsDescendantOf ) {
76
76
Assert .notNull (propertySource , "PropertySource must not be null" );
77
77
Assert .notNull (mapper , "Mapper must not be null" );
78
78
this .propertySource = propertySource ;
79
79
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 );
82
82
}
83
83
84
84
@ Override
@@ -91,7 +91,7 @@ public ConfigurationProperty getConfigurationProperty(
91
91
@ Override
92
92
public ConfigurationPropertyState containsDescendantOf (
93
93
ConfigurationPropertyName name ) {
94
- return this .containsDescendantOfMethod .apply (name );
94
+ return this .containsDescendantOf .apply (name );
95
95
}
96
96
97
97
@ Override
@@ -146,7 +146,7 @@ public static SpringConfigurationPropertySource from(PropertySource<?> source) {
146
146
(EnumerablePropertySource <?>) source , mapper );
147
147
}
148
148
return new SpringConfigurationPropertySource (source , mapper ,
149
- getContainsDescendantOfMethod (source ));
149
+ getContainsDescendantOfForSource (source ));
150
150
}
151
151
152
152
private static PropertyMapper getPropertyMapper (PropertySource <?> source ) {
@@ -178,16 +178,22 @@ private static PropertySource<?> getRootSource(PropertySource<?> source) {
178
178
return source ;
179
179
}
180
180
181
- private static Function <ConfigurationPropertyName , ConfigurationPropertyState > getContainsDescendantOfMethod (
181
+ private static Function <ConfigurationPropertyName , ConfigurationPropertyState > getContainsDescendantOfForSource (
182
182
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 ;
187
185
}
188
186
return null ;
189
187
}
190
188
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
+
191
197
/**
192
198
* {@link PropertyMapper} that swallows exceptions when the mapping fails.
193
199
*/
0 commit comments