From dd3f57d8166c50b73a3c4012e29310d751f0a85e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 2 May 2018 15:55:29 +0200 Subject: [PATCH] Avoid potentially mutating item metadata collection Closes gh-13027 --- .../metadata/ConfigurationMetadata.java | 10 ++++++++-- ...ConfigurationMetadataAnnotationProcessorTests.java | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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,