diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 700987f026..d54cb8ff0c 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -146,8 +146,8 @@ public class ConfigurationMetadata { } private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) { - List candidates = this.items.get(metadata.getName()); - if (candidates == null || candidates.isEmpty()) { + List candidates = getCandidates(metadata.getName()); + if (candidates.isEmpty()) { return null; } ListIterator it = candidates.listIterator(); @@ -167,6 +167,12 @@ public class ConfigurationMetadata { return null; } + private List getCandidates(String name) { + List candidates = this.items.get(name); + return (candidates != null ? new ArrayList(candidates) + : new ArrayList()); + } + private boolean nullSafeEquals(Object o1, Object o2) { if (o1 == o2) { return true; diff --git a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java index 1ada0d4809..0b33682279 100644 --- a/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java +++ b/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java @@ -543,6 +543,17 @@ public class ConfigurationMetadataAnnotationProcessorTests { .fromSource(AdditionalMetadata.class)); } + @Test + public void mergingOfAdditionalPropertyMatchingGroup() throws Exception { + ItemMetadata property = ItemMetadata.newProperty(null, "simple", + "java.lang.String", null, null, null, null, null); + writeAdditionalMetadata(property); + ConfigurationMetadata metadata = compile(SimpleProperties.class); + assertThat(metadata).has(Metadata.withGroup("simple") + .fromSource(SimpleProperties.class)); + assertThat(metadata).has(Metadata.withProperty("simple", String.class)); + } + @Test public void mergeExistingPropertyDefaultValue() throws Exception { ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null,