From 8e22f47916935e275da5e776f576672d7ef91096 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 25 Jul 2016 10:09:04 -0700 Subject: [PATCH] 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 --- .../boot/bind/PropertiesConfigurationFactory.java | 3 ++- .../EnableConfigurationPropertiesTests.java | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java index 37c17f8b214..e7bc44effab 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertiesConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -259,6 +259,7 @@ public class PropertiesConfigurationFactory if (this.conversionService != null) { dataBinder.setConversionService(this.conversionService); } + dataBinder.setAutoGrowCollectionLimit(Integer.MAX_VALUE); dataBinder.setIgnoreNestedProperties(this.ignoreNestedProperties); dataBinder.setIgnoreInvalidFields(this.ignoreInvalidFields); dataBinder.setIgnoreUnknownFields(this.ignoreUnknownFields); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java index 839ec10fb74..46b3a25f1e4 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/EnableConfigurationPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -210,6 +210,19 @@ public class EnableConfigurationPropertiesTests { assertEquals(2, this.context.getBean(TestProperties.class).getList().size()); } + @Test + public void testCollectionPropertiesBindingWithOver256Elements() { + this.context.register(TestConfiguration.class); + List pairs = new ArrayList(); + pairs.add("name:foo"); + for (int i = 0; i < 1000; i++) { + pairs.add("list[" + i + "]:" + i); + } + EnvironmentTestUtils.addEnvironment(this.context, pairs.toArray(new String[] {})); + this.context.refresh(); + assertEquals(1000, this.context.getBean(TestProperties.class).getList().size()); + } + @Test public void testPropertiesBindingWithoutAnnotation() { this.context.register(InvalidConfiguration.class);