Commit 8b298238 authored by Madhura Bhave's avatar Madhura Bhave

Prevent StackOverFlowException in metadata processor

Fixes gh-11037
parent 13f45e64
......@@ -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();
}
......
......@@ -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;
......
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