Skip to content

Commit bb13eaa

Browse files
committed
Support lower case configuration properties system environment names
Update `SystemEnvironmentPropertyMapper` to generate both mappings in both the original case and upper case. This restores the behavior of Spring Boot 3.4 where the system environment could contain lowercase names. Fixes gh-45741
1 parent 2f891c2 commit bb13eaa

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,25 +543,24 @@ ConfigurationPropertyName asSystemEnvironmentLegacyName() {
543543

544544
@Override
545545
public String toString() {
546-
return toString(ToStringFormat.DEFAULT);
546+
return toString(ToStringFormat.DEFAULT, false);
547547
}
548548

549-
String toString(ToStringFormat format) {
549+
String toString(ToStringFormat format, boolean upperCase) {
550550
String string = this.string[format.ordinal()];
551551
if (string == null) {
552552
string = buildToString(format);
553553
this.string[format.ordinal()] = string;
554554
}
555-
return string;
555+
return (!upperCase) ? string : string.toUpperCase(Locale.ENGLISH);
556556
}
557557

558558
private String buildToString(ToStringFormat format) {
559559
return switch (format) {
560560
case DEFAULT -> buildDefaultToString();
561-
case SYSTEM_ENVIRONMENT ->
562-
buildSimpleToString('_', (i) -> getElement(i, Form.UNIFORM).toUpperCase(Locale.ENGLISH));
563-
case LEGACY_SYSTEM_ENVIRONMENT -> buildSimpleToString('_',
564-
(i) -> getElement(i, Form.ORIGINAL).replace('-', '_').toUpperCase(Locale.ENGLISH));
561+
case SYSTEM_ENVIRONMENT -> buildSimpleToString('_', (i) -> getElement(i, Form.UNIFORM));
562+
case LEGACY_SYSTEM_ENVIRONMENT ->
563+
buildSimpleToString('_', (i) -> getElement(i, Form.ORIGINAL).replace('-', '_'));
565564
};
566565
}
567566

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringConfigurationPropertySource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context.properties.source;
1818

19+
import java.util.Locale;
1920
import java.util.Map;
2021
import java.util.Random;
2122

@@ -109,7 +110,8 @@ protected final Object getPropertySourceProperty(String name) {
109110
}
110111

111112
Object getSystemEnvironmentProperty(Map<String, Object> systemEnvironment, String name) {
112-
return systemEnvironment.get(name);
113+
Object value = systemEnvironment.get(name);
114+
return (value != null) ? value : systemEnvironment.get(name.toLowerCase(Locale.ROOT));
113115
}
114116

115117
@Override

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.context.properties.source;
1818

19-
import java.util.Arrays;
20-
import java.util.Collections;
2119
import java.util.List;
2220
import java.util.Locale;
2321
import java.util.function.BiPredicate;
@@ -42,12 +40,10 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
4240

4341
@Override
4442
public List<String> map(ConfigurationPropertyName configurationPropertyName) {
45-
String name = configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT);
46-
String legacyName = configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT);
47-
if (name.equals(legacyName)) {
48-
return Collections.singletonList(name);
49-
}
50-
return Arrays.asList(name, legacyName);
43+
return List.of(configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, true),
44+
configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, true),
45+
configurationPropertyName.toString(ToStringFormat.SYSTEM_ENVIRONMENT, false),
46+
configurationPropertyName.toString(ToStringFormat.LEGACY_SYSTEM_ENVIRONMENT, false));
5147
}
5248

5349
@Override

0 commit comments

Comments
 (0)