diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java index 04ee92ff8b97..f4292fdf5481 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java @@ -142,9 +142,7 @@ private Cache getCache() { } private Object getCacheKey() { - if (getPropertySource() instanceof MapPropertySource) { - return ((MapPropertySource) getPropertySource()).getSource().keySet(); - } + // gh-13344 return getPropertySource().getPropertyNames(); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java index f05cb1f5ec75..276fd8ac685f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java @@ -76,6 +76,7 @@ * @author Andy Wilkinson * @author Stephane Nicoll * @author Ben Hale + * @author Fahim Farook */ @RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions("log4j*.jar") @@ -500,12 +501,23 @@ public void systemPropertiesAreSetForLoggingConfiguration() { @Test public void environmentPropertiesIgnoreUnresolvablePlaceholders() { // gh-7719 + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, + "logging.pattern.console=console ${doesnotexist}"); + this.initializer.initialize(this.context.getEnvironment(), + this.context.getClassLoader()); + assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)) + .isEqualTo("console ${doesnotexist}"); + } + + @Test + public void environmentPropertiesResolvePlaceholders() { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "logging.pattern.console=console ${pid}"); this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader()); assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN)) - .isEqualTo("console ${pid}"); + .isEqualTo(this.context.getEnvironment() + .getProperty("logging.pattern.console")); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java index fd9a9d59b00c..abd59f3c2bc0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java @@ -37,6 +37,7 @@ * * @author Phillip Webb * @author Madhura Bhave + * @author Fahim Farook */ public class SpringIterableConfigurationPropertySourceTests { @@ -157,6 +158,24 @@ public void containsDescendantOfShouldCheckSourceNames() { .isEqualTo(ConfigurationPropertyState.ABSENT); } + @SuppressWarnings("unchecked") + @Test + public void propertySourceChangeReflects() { + // gh-13344 + final Map source = new LinkedHashMap<>(); + source.put("key1", "value1"); + source.put("key2", "value2"); + final EnumerablePropertySource propertySource = new MapPropertySource("test", + source); + final SpringIterableConfigurationPropertySource adapter = new SpringIterableConfigurationPropertySource( + propertySource, DefaultPropertyMapper.INSTANCE); + assertThat(adapter.stream().count()).isEqualTo(2); + + ((Map) adapter.getPropertySource().getSource()).put("key3", + "value3"); + assertThat(adapter.stream().count()).isEqualTo(3); + } + /** * Test {@link PropertySource} that's also an {@link OriginLookup}. */