From 0378de7b308a60449f62762bcea6d307dcc90e5b Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Fri, 5 Jun 2020 16:03:03 -0700 Subject: [PATCH] Optimize SystemEnvironmentPropertyMapper See gh-21523 --- .../source/SystemEnvironmentPropertyMapper.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java index c6632c4545..5b21e5f30d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java @@ -116,6 +116,16 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper { if (!hasDashedEntries(name)) { return false; } + StringBuilder legacyCompatibleName = buildLegacyCompatibleName(name); + try { + return ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate); + } + catch (Exception ex) { + return false; + } + } + + private StringBuilder buildLegacyCompatibleName(ConfigurationPropertyName name) { StringBuilder legacyCompatibleName = new StringBuilder(); for (int i = 0; i < name.getNumberOfElements(); i++) { if (i != 0) { @@ -123,8 +133,7 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper { } legacyCompatibleName.append(name.getElement(i, Form.DASHED).replace('-', '.')); } - return ConfigurationPropertyName.isValid(legacyCompatibleName) - && ConfigurationPropertyName.of(legacyCompatibleName).isAncestorOf(candidate); + return legacyCompatibleName; } boolean hasDashedEntries(ConfigurationPropertyName name) {