diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index 6be02e76d2..5fa9aa45d2 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -284,6 +284,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { * @since 5.3.4 * @see #ACTIVE_PROFILES_PROPERTY_NAME */ + @Nullable protected String doGetActiveProfilesProperty() { return getProperty(ACTIVE_PROFILES_PROPERTY_NAME); } @@ -350,6 +351,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { * @since 5.3.4 * @see #DEFAULT_PROFILES_PROPERTY_NAME */ + @Nullable protected String doGetDefaultProfilesProperty() { return getProperty(DEFAULT_PROFILES_PROPERTY_NAME); } diff --git a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java index a1666abcfb..7f35a190c8 100644 --- a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java @@ -24,6 +24,8 @@ import java.util.Set; import org.junit.jupiter.api.Test; +import org.springframework.lang.Nullable; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -34,8 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ class CustomEnvironmentTests { - // -- tests relating to customizing reserved default profiles ---------------------- - @Test void control() { Environment env = new AbstractEnvironment() { }; @@ -111,11 +111,12 @@ class CustomEnvironmentTests { public void withNoProfileProperties() { ConfigurableEnvironment env = new AbstractEnvironment() { @Override + @Nullable protected String doGetActiveProfilesProperty() { return null; } - @Override + @Nullable protected String doGetDefaultProfilesProperty() { return null; } @@ -140,23 +141,23 @@ class CustomEnvironmentTests { @Test void withCustomPropertyResolver() { class CustomPropertySourcesPropertyResolver extends PropertySourcesPropertyResolver { - public CustomPropertySourcesPropertyResolver( - PropertySources propertySources) { + public CustomPropertySourcesPropertyResolver(PropertySources propertySources) { super(propertySources); } - @Override + @Nullable public String getProperty(String key) { return super.getProperty(key)+"-test"; } } + ConfigurableEnvironment env = new AbstractEnvironment() { @Override - protected ConfigurablePropertyResolver createPropertyResolver( - MutablePropertySources propertySources) { + protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) { return new CustomPropertySourcesPropertyResolver(propertySources); } }; + Map values = new LinkedHashMap<>(); values.put("spring", "framework"); PropertySource propertySource = new MapPropertySource("test", values); @@ -168,6 +169,4 @@ class CustomEnvironmentTests { return Profiles.of(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME); } - - // -- tests relating to customizing property sources ------------------------------- }