Prevent StackOverFlowException in metadata processor

Fixes gh-11037
This commit is contained in:
Madhura Bhave 2018-03-27 10:56:29 -07:00
parent 13f45e6434
commit 8b29823885
2 changed files with 14 additions and 3 deletions

View File

@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties;
@ -115,7 +114,6 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
}
@Test
@Ignore("gh-11037")
public void testCycle() {
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(CycleConfig.class);
@ -516,7 +514,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
@Bean
// gh-11037
// @ConfigurationProperties(prefix = "cycle")
@ConfigurationProperties(prefix = "cycle")
public Cycle cycle() {
return new Cycle();
}

View File

@ -468,10 +468,23 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
if (hasAnnotation(field, nestedConfigurationPropertyAnnotation())) {
return true;
}
if (isCyclePresent(returnType, element)) {
return false;
}
return (isParentTheSame(returnType, element))
&& returnType.getKind() != ElementKind.ENUM;
}
private boolean isCyclePresent(Element returnType, Element element) {
if (!(element.getEnclosingElement() instanceof TypeElement)) {
return false;
}
if (element.getEnclosingElement().equals(returnType)) {
return true;
}
return isCyclePresent(returnType, element.getEnclosingElement());
}
private boolean isParentTheSame(Element returnType, TypeElement element) {
if (returnType == null || element == null) {
return false;