Repository navigation
Description
When properties are imported with spring.config.import=configtree:..., binding a value fails with ConverterNotFoundException if a collection with the same element type was bound from the same config tree before it. If the single value is bound first, both bind fine. The example below uses Set<Integer> and Integer; the other types I tried are listed further down.
Versions: reproduced on Spring Boot 4.2.0-RC1, 4.1.2, 4.0.9, 3.5.16, 3.4.13, 3.3.13, 3.2.12, 3.1.12, 3.0.13, 2.7.18 and 2.5.0, with JDK 21 and 25. Spring Boot 2.4.13 starts fine with the same sample.
Reproduction
configtree/collection.ids, no trailing newline:
254,169,1413
configtree/scalar.timeout:
300000
application.properties:
spring.config.import=configtree:configtree/@ConfigurationProperties("collection")
public record CollectionProperties(Set<Integer> ids) {}
@ConfigurationProperties("scalar")
public record ScalarProperties(Integer timeout) {}
@SpringBootApplication
@EnableConfigurationProperties({ CollectionProperties.class, ScalarProperties.class })
public class ReproApplication {
public static void main(String[] args) {
SpringApplication.run(ReproApplication.class, args);
}
// CollectionProperties is bound before ScalarProperties (parameter order)
@Bean
ApplicationRunner printer(CollectionProperties collection, ScalarProperties scalar) {
return (args) -> System.out.println("Bound " + collection + " and " + scalar);
}
}Run it from the project root with ./mvnw spring-boot:run.
Expected: the application starts and prints Bound CollectionProperties[ids=[254, 169, 1413]] and ScalarProperties[timeout=300000].
Actual:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'scalar.timeout' to java.lang.Integer:
Property: scalar.timeout
Value: "300000"
Origin: file [.../configtree/scalar.timeout] - 1:1
Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.boot.env.ConfigTreePropertySource$PropertyFileContent] to type [java.lang.Integer]
Controls
- Reverse order. Same config tree, but
ScalarPropertiesis bound beforeCollectionProperties: the application starts and both properties bind. - String values. Same values as plain properties instead of a config tree (
collection.ids=254,169,1413,scalar.timeout=300000), withCollectionPropertiesbound first: the application starts and both properties bind.
Without an application context
The same happens with a Binder alone:
Binder binder = new Binder(
List.of(ConfigurationPropertySource.from(new ConfigTreePropertySource("tree", Path.of("configtree")))), null,
new ApplicationConversionService());
binder.bind("collection.ids", Bindable.setOf(Integer.class)).get(); // [254, 169, 1413]
binder.bind("scalar.timeout", Integer.class).get(); // BindException, cause: ConverterNotFoundExceptionIt can also be observed on an ApplicationConversionService directly:
Object value = new ConfigTreePropertySource("tree", Path.of("configtree")).getProperty("scalar.timeout");
TypeDescriptor source = TypeDescriptor.forObject(value);
TypeDescriptor setOfInteger = new TypeDescriptor(ResolvableType.forClassWithGenerics(Set.class, Integer.class), null, null);
ApplicationConversionService conversionService = new ApplicationConversionService();
conversionService.canConvert(source, setOfInteger); // true
conversionService.canConvert(source, TypeDescriptor.valueOf(Integer.class)); // falseCalled in the reverse order on a new ApplicationConversionService, both calls return true.
The same happens with List<T> and T[] instead of Set<T>, and for every other element type I tried that needs a conversion: Long, Short, Byte, Double, Float, Boolean, Character, BigDecimal, BigInteger, UUID, LocalDate, Duration, Period, DataSize, an enum, Locale, Charset and URI. String elements, primitive targets (for example int after Set<Integer>) and the reverse order are not affected.
Sample project with all of the above as tests, including every element type and collection kind listed (./mvnw test: 106 tests, 60 fail, 46 pass; -Dspring-boot.version=… to switch versions): https://github.com/artem1458/spring-boot-configtree-binding-repro
AI disclosure: the investigation, the sample project and this text were prepared with an AI agent (Claude Code) and reviewed by me before posting.
Activity
[-]Binding an Integer from a config tree fails after a Set<Integer> has been bound from the same config tree[/-][+]Binding a value from a config tree fails after a collection of the same element type has been bound from the same config tree[/+]wilkinsona commentedon Nov 2, 2026
This is caused by
CharSequenceToObjectConverterpolluting theconverterCachewith aNO_MATCHentry forPropertyFileContent -> Integer. The entry is added whenObjectToCollectionConverteris checking if it can convert the elements. It's aNO_MATCHbecause of thedisablethread local thatCharSequenceToObjectConvertersets when it checks thePropertyFileContent -> Set<Integer>conversion that then spills over into the elements conversion check.If
PropertyFileContent -> Integeris checked first, the pollution of the cache doesn't happen and things work as expected.wilkinsona commentedon Nov 2, 2026
This test passes:
After the first conversion, the cache looks like this:
This test fails:
After the first conversion, the cache looks like this:
It's the second entry in the cache that's the pollution and that causes the failure.
Protect against converter cache pollution
challa commentedon Nov 4, 2026
ConfigurationPropertiesCharSequenceToObjectConverter, the copy ofCharSequenceToObjectConverterthatConversionServiceDeduceruses when there are@ConfigurationPropertiesBindingconverters, still has thedisablethread local that 7c1bef5 replaced. The same cache pollution still happens for types that require one of these custom converters.With a config tree containing
custom.endpoints(a:1,b:2) andcustom.primary(c:3), this fails to start on4.0.10-SNAPSHOT,4.1.3-SNAPSHOTand4.2.0-SNAPSHOT, tested on November 4.Import the directory using
spring.config.import=configtree:configtree/, enableCustomPropertieswith@EnableConfigurationProperties(CustomProperties.class), and declare the converter bean in the application configuration:Declaring
primarybeforeendpointsworks. Applying the same change to the copy fixes it; I have that change with a test on a branch based on4.0.xI used an AI coding assistant for parts of the analysis; I reviewed and verified it myself.
wilkinsona commentedon Nov 4, 2026
Well spotted, @challa, thank you. I have made the necessary changes in 00cfa0d.
Apply 7c1bef5 to ConfigurationProperties converter variant