Skip to content

Commit 0b638f3

Browse files
committed
Merge branch 'main' into 4.0.x
2 parents e342c35 + 5695192 commit 0b638f3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ private void tryUpdate(EnumerablePropertySource<?> propertySource) {
274274
if (configurationPropertyName != null && !configurationPropertyName.isEmpty()) {
275275
add(mappings, configurationPropertyName, propertyName);
276276
reverseMappings.put(propertyName, configurationPropertyName);
277-
addParents(descendants, configurationPropertyName);
278277
}
279278
}
280279
}
281280
}
281+
for (String propertyName : propertyNames) {
282+
addParents(descendants, reverseMappings.get(propertyName));
283+
}
282284
ConfigurationPropertyName[] configurationPropertyNames = this.immutable
283285
? reverseMappings.values().toArray(new ConfigurationPropertyName[0]) : null;
284286
lastUpdated = this.immutable ? null : propertyNames;
@@ -296,7 +298,7 @@ private <K, V> Map<K, V> cloneOrCreate(Map<K, V> source, int size) {
296298
}
297299

298300
private void addParents(Set<ConfigurationPropertyName> descendants, ConfigurationPropertyName name) {
299-
if (descendants == null || name.isEmpty()) {
301+
if (descendants == null || name == null || name.isEmpty()) {
300302
return;
301303
}
302304
ConfigurationPropertyName parent = name.getParent();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ void orderOfUnderlyingSourceIsPreserved() {
239239
"test.map.bravo", "test.map.charlie", "test.map.delta");
240240
}
241241

242+
@Test
243+
void cacheRefreshRecalculatesDescendants() {
244+
// gh-45639
245+
Map<String, Object> map = new LinkedHashMap<>();
246+
map.put("one.two.three", "test");
247+
EnumerablePropertySource<?> source = new OriginTrackedMapPropertySource("test", map, false);
248+
SpringIterableConfigurationPropertySource propertySource = new SpringIterableConfigurationPropertySource(source,
249+
false, DefaultPropertyMapper.INSTANCE);
250+
assertThat(propertySource.containsDescendantOf(ConfigurationPropertyName.of("one.two")))
251+
.isEqualTo(ConfigurationPropertyState.PRESENT);
252+
map.put("new", "value");
253+
assertThat(propertySource.containsDescendantOf(ConfigurationPropertyName.of("one.two")))
254+
.isEqualTo(ConfigurationPropertyState.PRESENT);
255+
}
256+
242257
/**
243258
* Test {@link PropertySource} that's also an {@link OriginLookup}.
244259
*

0 commit comments

Comments
 (0)