diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java index 4f3b0d65ffde..814bd1aa7398 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/Binder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -367,7 +367,7 @@ private T handleBindError(ConfigurationPropertyName name, Bindable target private Object bindObject(ConfigurationPropertyName name, Bindable target, BindHandler handler, Context context, boolean allowRecursiveBinding) { ConfigurationProperty property = findProperty(name, context); - if (property == null && containsNoDescendantOf(context.getSources(), name) && context.depth != 0) { + if (property == null && context.depth != 0 && containsNoDescendantOf(context.getSources(), name)) { return null; } AggregateBinder aggregateBinder = getAggregateBinder(target, context); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java index 6ccdd3a3ae54..b799aa00804b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -101,7 +101,7 @@ private void bindValue(Bindable target, Collection collection, Resolv private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root, AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType elementType) { - MultiValueMap knownIndexedChildren = getKnownIndexedChildren(source, root); + MultiValueMap knownIndexedChildren = getKnownIndexedChildren(source, root); for (int i = 0; i < Integer.MAX_VALUE; i++) { ConfigurationPropertyName name = root.append((i != 0) ? "[" + i + "]" : INDEX_ZERO); Object value = elementBinder.bind(name, Bindable.of(elementType), source); @@ -111,12 +111,12 @@ private void bindIndexed(ConfigurationPropertySource source, ConfigurationProper knownIndexedChildren.remove(name.getLastElement(Form.UNIFORM)); collection.get().add(value); } - assertNoUnboundChildren(knownIndexedChildren); + assertNoUnboundChildren(source, knownIndexedChildren); } - private MultiValueMap getKnownIndexedChildren(ConfigurationPropertySource source, + private MultiValueMap getKnownIndexedChildren(ConfigurationPropertySource source, ConfigurationPropertyName root) { - MultiValueMap children = new LinkedMultiValueMap<>(); + MultiValueMap children = new LinkedMultiValueMap<>(); if (!(source instanceof IterableConfigurationPropertySource)) { return children; } @@ -124,17 +124,17 @@ private MultiValueMap getKnownIndexedChildren(Con ConfigurationPropertyName choppedName = name.chop(root.getNumberOfElements() + 1); if (choppedName.isLastElementIndexed()) { String key = choppedName.getLastElement(Form.UNIFORM); - ConfigurationProperty value = source.getConfigurationProperty(name); - children.add(key, value); + children.add(key, name); } } return children; } - private void assertNoUnboundChildren(MultiValueMap children) { + private void assertNoUnboundChildren(ConfigurationPropertySource source, + MultiValueMap children) { if (!children.isEmpty()) { - throw new UnboundConfigurationPropertiesException( - children.values().stream().flatMap(List::stream).collect(Collectors.toCollection(TreeSet::new))); + throw new UnboundConfigurationPropertiesException(children.values().stream().flatMap(List::stream) + .map(source::getConfigurationProperty).collect(Collectors.toCollection(TreeSet::new))); } }