Skip to content

Commit 8e22f47

Browse files
committed
Don't limit collection sizes in property binding
Update PropertiesConfigurationFactory so that collections can grow beyond 256 items. Prior to this commit configuration property binding used the default `DataBinder.autoGrowNestedPaths` setting of 256. Fixes gh-6436
1 parent 6a8620a commit 8e22f47

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -259,6 +259,7 @@ private void doBindPropertiesToTarget() throws BindException {
259259
if (this.conversionService != null) {
260260
dataBinder.setConversionService(this.conversionService);
261261
}
262+
dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE);
262263
dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties);
263264
dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields);
264265
dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields);

spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -210,6 +210,19 @@ public void testCollectionPropertiesBindingFromYamlArray() {
210210
assertEquals(2, this.context.getBean(TestProperties.class).getList().size());
211211
}
212212

213+
@Test
214+
public void testCollectionPropertiesBindingWithOver256Elements() {
215+
this.context.register(TestConfiguration.class);
216+
List<String> pairs = new ArrayList<String>();
217+
pairs.add("name:foo");
218+
for (int i = 0; i < 1000; i++) {
219+
pairs.add("list[" + i + "]:" + i);
220+
}
221+
EnvironmentTestUtils.addEnvironment(this.context, pairs.toArray(new String[] {}));
222+
this.context.refresh();
223+
assertEquals(1000, this.context.getBean(TestProperties.class).getList().size());
224+
}
225+
213226
@Test
214227
public void testPropertiesBindingWithoutAnnotation() {
215228
this.context.register(InvalidConfiguration.class);

0 commit comments

Comments
 (0)