diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index c0f19d972c..a7fa9d8a69 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -145,6 +145,9 @@ public final class ConfigurationPropertyName * @return {@code true} if this name is an ancestor */ public boolean isAncestorOf(ConfigurationPropertyName name) { + if (this.equals(EMPTY)) { + return true; + } ConfigurationPropertyName candidate = (name == null ? null : name.getParent()); while (candidate != null) { if (candidate.equals(this)) { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java index a0df87b141..695995515a 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java @@ -274,6 +274,15 @@ public class ConfigurationPropertyNameTests { assertThat(grandchild.isAncestorOf(parent)).isFalse(); } + @Test + public void isAncestorOfWhenRootReturnTrue() throws Exception { + ConfigurationPropertyName parent = ConfigurationPropertyName.of(""); + ConfigurationPropertyName grandchild = ConfigurationPropertyName + .of("foo.bar.baz"); + assertThat(parent.isAncestorOf(grandchild)).isTrue(); + assertThat(grandchild.isAncestorOf(parent)).isFalse(); + } + @Test public void appendWhenNotIndexedShouldAppendWithDot() throws Exception { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");