Commit 99ad79db authored by Madhura Bhave's avatar Madhura Bhave Committed by Phillip Webb

Add tests to trigger binder stack overflow error

Update `CollectionBinderTests` with additional tests that cause a
`StackOverflowException` due to recursive list binding.

See gh-10702
parent 861469fb
......@@ -351,6 +351,32 @@ public class CollectionBinderTests {
assertThat(result.getItemsSet()).containsExactly("a", "b", "c");
}
public void bindToBeanWithNestedCollectionShouldPopulateCollection()
throws Exception {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo.value", "one");
source.put("foo.foos[0].value", "two");
source.put("foo.foos[1].value", "three");
this.sources.add(source);
Bindable<BeanWithNestedCollection> target = Bindable
.of(BeanWithNestedCollection.class);
BeanWithNestedCollection foo = this.binder.bind("foo", target).get();
assertThat(foo.getValue()).isNotNull();
assertThat(foo.getFoos().get(0).getValue()).isEqualTo("two");
assertThat(foo.getFoos().get(1).getValue()).isEqualTo("three");
}
@Test
public void bindToBeanWithNestedCollectionAndNonIterableSourceShouldNotFail()
throws Exception {
// gh-10702
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
this.sources.add(source.nonIterable());
Bindable<BeanWithNestedCollection> target = Bindable
.of(BeanWithNestedCollection.class);
this.binder.bind("foo", target);
}
public static class ExampleCollectionBean {
private List<String> items = new ArrayList<>();
......@@ -401,4 +427,27 @@ public class CollectionBinderTests {
}
public static class BeanWithNestedCollection {
private String value;
private List<BeanWithNestedCollection> foos;
public List<BeanWithNestedCollection> getFoos() {
return this.foos;
}
public void setFoos(List<BeanWithNestedCollection> foos) {
this.foos = foos;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment