Prevent recursive config props from causing a stack overflow
Previously, when the configuration properties annotation processor encountered a property that was the same as an outer type that had already been processed, it would fail with a stack overflow error. This commit introduces the use of a stack to track the types that have been processed. Types that have been seen before are skipped, thereby preventing a failure from occurring. We do not fail upon encountering a recursive type to allow metadata generation to complete. At runtime, the recursive property will not cause a problem if it is not bound. Fixes gh-18365
This commit is contained in:
@@ -68,6 +68,7 @@ import org.springframework.boot.configurationsample.method.EmptyTypeMethodConfig
|
||||
import org.springframework.boot.configurationsample.method.InvalidMethodConfig;
|
||||
import org.springframework.boot.configurationsample.method.MethodAndClassConfig;
|
||||
import org.springframework.boot.configurationsample.method.SimpleMethodConfig;
|
||||
import org.springframework.boot.configurationsample.recursive.RecursiveProperties;
|
||||
import org.springframework.boot.configurationsample.simple.ClassWithNestedProperties;
|
||||
import org.springframework.boot.configurationsample.simple.DeprecatedFieldSingleProperty;
|
||||
import org.springframework.boot.configurationsample.simple.DeprecatedSingleProperty;
|
||||
@@ -970,6 +971,11 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
.has(Metadata.withProperty("bar.counter").withDefaultValue(0).fromSource(RenamedBarProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursivePropertiesDoNotCauseAStackOverflow() {
|
||||
compile(RecursiveProperties.class);
|
||||
}
|
||||
|
||||
private void assertSimpleLombokProperties(ConfigurationMetadata metadata, Class<?> source, String prefix) {
|
||||
assertThat(metadata).has(Metadata.withGroup(prefix).fromSource(source));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty(prefix + ".id"));
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user