Skip to content

Commit 18e5e06

Browse files
committed
Merge branch '3.4.x'
Closes gh-46040
2 parents 01a23c3 + cb9cf45 commit 18e5e06

File tree

2 files changed

+27
-0
lines changed
  • spring-boot-project/spring-boot/src

2 files changed

+27
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,15 @@ private <T> T withSource(ConfigurationPropertySource source, Supplier<T> supplie
576576
if (source == null) {
577577
return supplier.get();
578578
}
579+
ConfigurationPropertySource previous = this.source.get(0);
579580
this.source.set(0, source);
580581
this.sourcePushCount++;
581582
try {
582583
return supplier.get();
583584
}
584585
finally {
585586
this.sourcePushCount--;
587+
this.source.set(0, previous);
586588
}
587589
}
588590

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ void bindToCollectionWhenNonKnownIndexedChildNotBoundThrowsException() {
143143
});
144144
}
145145

146+
@Test
147+
void bindToNestedCollectionWhenNonKnownIndexed() {
148+
// gh-46039
149+
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
150+
source.put("foo[0].items[0]", "a");
151+
source.put("foo[0].items[1]", "b");
152+
source.put("foo[0].string", "test");
153+
this.sources.add(source);
154+
List<ExampleCollectionBean> list = this.binder.bind("foo", Bindable.listOf(ExampleCollectionBean.class)).get();
155+
assertThat(list).hasSize(1);
156+
ExampleCollectionBean bean = list.get(0);
157+
assertThat(bean.getItems()).containsExactly("a", "b", "d");
158+
assertThat(bean.getString()).isEqualTo("test");
159+
}
160+
146161
@Test
147162
void bindToNonScalarCollectionWhenNonSequentialShouldThrowException() {
148163
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
@@ -456,6 +471,8 @@ static class ExampleCollectionBean {
456471

457472
private Set<String> itemsSet = new LinkedHashSet<>();
458473

474+
private String string;
475+
459476
List<String> getItems() {
460477
return this.items;
461478
}
@@ -472,6 +489,14 @@ void setItemsSet(Set<String> itemsSet) {
472489
this.itemsSet = itemsSet;
473490
}
474491

492+
String getString() {
493+
return this.string;
494+
}
495+
496+
void setString(String string) {
497+
this.string = string;
498+
}
499+
475500
}
476501

477502
static class ExampleCustomNoDefaultConstructorBean {

0 commit comments

Comments
 (0)