From 99ad79dbe6aee1209b2800c9c9bd5362b56e9959 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Sat, 4 Nov 2017 22:14:51 -0700 Subject: [PATCH] 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 --- .../bind/CollectionBinderTests.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java index 8779d5738f..7479a8dfaa 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/CollectionBinderTests.java @@ -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 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 target = Bindable + .of(BeanWithNestedCollection.class); + this.binder.bind("foo", target); + } + public static class ExampleCollectionBean { private List items = new ArrayList<>(); @@ -401,4 +427,27 @@ public class CollectionBinderTests { } + public static class BeanWithNestedCollection { + + private String value; + + private List foos; + + public List getFoos() { + return this.foos; + } + + public void setFoos(List foos) { + this.foos = foos; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + } + }