Avoid potentially mutating item metadata collection

Closes gh-13027
pull/13050/head
Stephane Nicoll 7 years ago
parent d0f329caa4
commit dd3f57d816

@ -146,8 +146,8 @@ public class ConfigurationMetadata {
}
private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) {
List<ItemMetadata> candidates = this.items.get(metadata.getName());
if (candidates == null || candidates.isEmpty()) {
List<ItemMetadata> candidates = getCandidates(metadata.getName());
if (candidates.isEmpty()) {
return null;
}
ListIterator<ItemMetadata> it = candidates.listIterator();
@ -167,6 +167,12 @@ public class ConfigurationMetadata {
return null;
}
private List<ItemMetadata> getCandidates(String name) {
List<ItemMetadata> candidates = this.items.get(name);
return (candidates != null ? new ArrayList<ItemMetadata>(candidates)
: new ArrayList<ItemMetadata>());
}
private boolean nullSafeEquals(Object o1, Object o2) {
if (o1 == o2) {
return true;

@ -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,

Loading…
Cancel
Save