Commit f1af8c55 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.1.x'

Closes gh-18889
parents d8545bde 59bc3c56
...@@ -25,6 +25,7 @@ import java.util.LinkedHashMap; ...@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Stack;
import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
...@@ -180,10 +181,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -180,10 +181,10 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if (annotation != null) { if (annotation != null) {
String prefix = getPrefix(annotation); String prefix = getPrefix(annotation);
if (element instanceof TypeElement) { if (element instanceof TypeElement) {
processAnnotatedTypeElement(prefix, (TypeElement) element); processAnnotatedTypeElement(prefix, (TypeElement) element, new Stack<TypeElement>());
} }
else if (element instanceof ExecutableElement) { else if (element instanceof ExecutableElement) {
processExecutableElement(prefix, (ExecutableElement) element); processExecutableElement(prefix, (ExecutableElement) element, new Stack<TypeElement>());
} }
} }
} }
...@@ -192,13 +193,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -192,13 +193,13 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
} }
} }
private void processAnnotatedTypeElement(String prefix, TypeElement element) { private void processAnnotatedTypeElement(String prefix, TypeElement element, Stack<TypeElement> seen) {
String type = this.metadataEnv.getTypeUtils().getQualifiedName(element); String type = this.metadataEnv.getTypeUtils().getQualifiedName(element);
this.metadataCollector.add(ItemMetadata.newGroup(prefix, type, type, null)); this.metadataCollector.add(ItemMetadata.newGroup(prefix, type, type, null));
processTypeElement(prefix, element, null); processTypeElement(prefix, element, null, seen);
} }
private void processExecutableElement(String prefix, ExecutableElement element) { private void processExecutableElement(String prefix, ExecutableElement element, Stack<TypeElement> seen) {
if ((!element.getModifiers().contains(Modifier.PRIVATE)) if ((!element.getModifiers().contains(Modifier.PRIVATE))
&& (TypeKind.VOID != element.getReturnType().getKind())) { && (TypeKind.VOID != element.getReturnType().getKind())) {
Element returns = this.processingEnv.getTypeUtils().asElement(element.getReturnType()); Element returns = this.processingEnv.getTypeUtils().asElement(element.getReturnType());
...@@ -213,22 +214,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor ...@@ -213,22 +214,27 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
} }
else { else {
this.metadataCollector.add(group); this.metadataCollector.add(group);
processTypeElement(prefix, (TypeElement) returns, element); processTypeElement(prefix, (TypeElement) returns, element, seen);
} }
} }
} }
} }
private void processTypeElement(String prefix, TypeElement element, ExecutableElement source) { private void processTypeElement(String prefix, TypeElement element, ExecutableElement source,
new PropertyDescriptorResolver(this.metadataEnv).resolve(element, source).forEach((descriptor) -> { Stack<TypeElement> seen) {
this.metadataCollector.add(descriptor.resolveItemMetadata(prefix, this.metadataEnv)); if (!seen.contains(element)) {
if (descriptor.isNested(this.metadataEnv)) { seen.push(element);
TypeElement nestedTypeElement = (TypeElement) this.metadataEnv.getTypeUtils() new PropertyDescriptorResolver(this.metadataEnv).resolve(element, source).forEach((descriptor) -> {
.asElement(descriptor.getType()); this.metadataCollector.add(descriptor.resolveItemMetadata(prefix, this.metadataEnv));
String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, descriptor.getName()); if (descriptor.isNested(this.metadataEnv)) {
processTypeElement(nestedPrefix, nestedTypeElement, source); TypeElement nestedTypeElement = (TypeElement) this.metadataEnv.getTypeUtils()
} .asElement(descriptor.getType());
}); String nestedPrefix = ConfigurationMetadata.nestedPrefix(prefix, descriptor.getName());
processTypeElement(nestedPrefix, nestedTypeElement, source, seen);
}
});
seen.pop();
}
} }
private void processEndpoint(Element element, List<Element> annotations) { private void processEndpoint(Element element, List<Element> annotations) {
......
...@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test; ...@@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata; import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.Metadata; import org.springframework.boot.configurationprocessor.metadata.Metadata;
import org.springframework.boot.configurationsample.recursive.RecursiveProperties;
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties; import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
import org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty; import org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty;
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty; import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
...@@ -361,4 +362,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene ...@@ -361,4 +362,9 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
.withMessageContaining("Compilation failed"); .withMessageContaining("Compilation failed");
} }
@Test
void recursivePropertiesDoNotCauseAStackOverflow() {
compile(RecursiveProperties.class);
}
} }
/*
* Copyright 2012-2018 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.configurationsample.recursive;
import org.springframework.boot.configurationsample.ConfigurationProperties;
@ConfigurationProperties("prefix")
public class RecursiveProperties {
private RecursiveProperties recursive;
public RecursiveProperties getRecursive() {
return this.recursive;
}
public void setRecursive(RecursiveProperties recursive) {
this.recursive = recursive;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment