Skip to content

Commit 7135527

Browse files
committed
Always obtain fresh PropertySources in ConfigurableEnvironmentPropertySource
Although it's unlikely that the implementation of getPropertySources() in a ConfigurableEnvironment would be overridden to return a different MutablePropertySources instance than the one that the ConfigurableEnvironment typically acts on, it is in fact possible. In light of that possibility, this commit refactors ConfigurableEnvironmentPropertySource so that it always obtains a fresh PropertySources reference. See gh-34861
1 parent 65e3013 commit 7135527

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,15 @@ public PropertySources getAppliedPropertySources() throws IllegalStateException
227227
*/
228228
private static class ConfigurableEnvironmentPropertySource extends PropertySource<ConfigurableEnvironment> {
229229

230-
private final PropertySources propertySources;
231-
232-
233230
ConfigurableEnvironmentPropertySource(ConfigurableEnvironment environment) {
234231
super(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, environment);
235-
this.propertySources = environment.getPropertySources();
236232
}
237233

238234

239235
@Override
240236
@Nullable
241237
public Object getProperty(String name) {
242-
for (PropertySource<?> propertySource : this.propertySources) {
238+
for (PropertySource<?> propertySource : super.source.getPropertySources()) {
243239
Object candidate = propertySource.getProperty(name);
244240
if (candidate != null) {
245241
return candidate;
@@ -250,7 +246,7 @@ public Object getProperty(String name) {
250246

251247
@Override
252248
public boolean containsProperty(String name) {
253-
for (PropertySource<?> propertySource : this.propertySources) {
249+
for (PropertySource<?> propertySource : super.source.getPropertySources()) {
254250
if (propertySource.containsProperty(name)) {
255251
return true;
256252
}
@@ -260,7 +256,7 @@ public boolean containsProperty(String name) {
260256

261257
@Override
262258
public String toString() {
263-
return "ConfigurableEnvironmentPropertySource {propertySources=" + this.propertySources + "}";
259+
return "ConfigurableEnvironmentPropertySource {propertySources=" + super.source.getPropertySources() + "}";
264260
}
265261
}
266262

0 commit comments

Comments
 (0)