Skip to content

Commit 9417975

Browse files
committed
Nullability refinements
See gh-26462
1 parent ed9ec58 commit 9417975

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ protected Set<String> doGetActiveProfiles() {
284284
* @since 5.3.4
285285
* @see #ACTIVE_PROFILES_PROPERTY_NAME
286286
*/
287+
@Nullable
287288
protected String doGetActiveProfilesProperty() {
288289
return getProperty(ACTIVE_PROFILES_PROPERTY_NAME);
289290
}
@@ -350,6 +351,7 @@ protected Set<String> doGetDefaultProfiles() {
350351
* @since 5.3.4
351352
* @see #DEFAULT_PROFILES_PROPERTY_NAME
352353
*/
354+
@Nullable
353355
protected String doGetDefaultProfilesProperty() {
354356
return getProperty(DEFAULT_PROFILES_PROPERTY_NAME);
355357
}

spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
import org.junit.jupiter.api.Test;
2626

27+
import org.springframework.lang.Nullable;
28+
2729
import static org.assertj.core.api.Assertions.assertThat;
2830

2931
/**
@@ -34,8 +36,6 @@
3436
*/
3537
class CustomEnvironmentTests {
3638

37-
// -- tests relating to customizing reserved default profiles ----------------------
38-
3939
@Test
4040
void control() {
4141
Environment env = new AbstractEnvironment() { };
@@ -111,11 +111,12 @@ protected Set<String> getReservedDefaultProfiles() {
111111
public void withNoProfileProperties() {
112112
ConfigurableEnvironment env = new AbstractEnvironment() {
113113
@Override
114+
@Nullable
114115
protected String doGetActiveProfilesProperty() {
115116
return null;
116117
}
117-
118118
@Override
119+
@Nullable
119120
protected String doGetDefaultProfilesProperty() {
120121
return null;
121122
}
@@ -140,23 +141,23 @@ class CustomMutablePropertySources extends MutablePropertySources {}
140141
@Test
141142
void withCustomPropertyResolver() {
142143
class CustomPropertySourcesPropertyResolver extends PropertySourcesPropertyResolver {
143-
public CustomPropertySourcesPropertyResolver(
144-
PropertySources propertySources) {
144+
public CustomPropertySourcesPropertyResolver(PropertySources propertySources) {
145145
super(propertySources);
146146
}
147-
148147
@Override
148+
@Nullable
149149
public String getProperty(String key) {
150150
return super.getProperty(key)+"-test";
151151
}
152152
}
153+
153154
ConfigurableEnvironment env = new AbstractEnvironment() {
154155
@Override
155-
protected ConfigurablePropertyResolver createPropertyResolver(
156-
MutablePropertySources propertySources) {
156+
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) {
157157
return new CustomPropertySourcesPropertyResolver(propertySources);
158158
}
159159
};
160+
160161
Map<String, Object> values = new LinkedHashMap<>();
161162
values.put("spring", "framework");
162163
PropertySource<?> propertySource = new MapPropertySource("test", values);
@@ -168,6 +169,4 @@ private Profiles defaultProfile() {
168169
return Profiles.of(AbstractEnvironment.RESERVED_DEFAULT_PROFILE_NAME);
169170
}
170171

171-
172-
// -- tests relating to customizing property sources -------------------------------
173172
}

0 commit comments

Comments
 (0)