Skip to content

Commit 009bd44

Browse files
committed
Improve null-safety of core/spring-boot
See gh-46926
1 parent a6b4400 commit 009bd44

File tree

8 files changed

+14
-11
lines changed

8 files changed

+14
-11
lines changed

core/spring-boot/src/main/java/org/springframework/boot/ApplicationInfoPropertySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ApplicationInfoPropertySource extends MapPropertySource implements OriginL
4444
super(NAME, getProperties(readVersion(mainClass)));
4545
}
4646

47-
ApplicationInfoPropertySource(String applicationVersion) {
47+
ApplicationInfoPropertySource(@Nullable String applicationVersion) {
4848
super(NAME, getProperties(applicationVersion));
4949
}
5050

core/spring-boot/src/main/java/org/springframework/boot/DefaultPropertiesPropertySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static boolean hasMatchingName(@Nullable PropertySource<?> propertySource
6969
* @param action the action used to consume the
7070
* {@link DefaultPropertiesPropertySource}
7171
*/
72-
public static void ifNotEmpty(Map<String, Object> source,
72+
public static void ifNotEmpty(@Nullable Map<String, Object> source,
7373
@Nullable Consumer<DefaultPropertiesPropertySource> action) {
7474
if (!CollectionUtils.isEmpty(source) && action != null) {
7575
action.accept(new DefaultPropertiesPropertySource(source));

core/spring-boot/src/main/java/org/springframework/boot/ResourceBanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private MapWithNullsPropertySource getVersionSource(Environment environment, @Nu
155155
return environment.getProperty("spring.application.version");
156156
}
157157

158-
protected String getBootVersion() {
158+
protected @Nullable String getBootVersion() {
159159
return SpringBootVersion.getVersion();
160160
}
161161

core/spring-boot/src/main/java/org/springframework/boot/context/annotation/Configurations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected Configurations(Collection<Class<?>> classes) {
8888
* @since 3.4.0
8989
*/
9090
protected Configurations(@Nullable UnaryOperator<Collection<Class<?>>> sorter, Collection<Class<?>> classes,
91-
Function<Class<?>, String> beanNameGenerator) {
91+
@Nullable Function<Class<?>, String> beanNameGenerator) {
9292
Assert.notNull(classes, "'classes' must not be null");
9393
this.sorter = (sorter != null) ? sorter : UnaryOperator.identity();
9494
Collection<Class<?>> sorted = this.sorter.apply(classes);

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataActivationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ConfigDataActivationContext {
5252
* @param cloudPlatform the cloud platform
5353
* @param profiles the profiles
5454
*/
55-
ConfigDataActivationContext(@Nullable CloudPlatform cloudPlatform, Profiles profiles) {
55+
ConfigDataActivationContext(@Nullable CloudPlatform cloudPlatform, @Nullable Profiles profiles) {
5656
this.cloudPlatform = cloudPlatform;
5757
this.profiles = profiles;
5858
}

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,10 @@ static ConfigDataEnvironmentContributor ofExisting(PropertySource<?> propertySou
440440
* @param environmentUpdateListener the environment update listener
441441
* @return a new {@link ConfigDataEnvironmentContributor} instance
442442
*/
443-
static ConfigDataEnvironmentContributor ofUnboundImport(ConfigDataLocation location, ConfigDataResource resource,
444-
boolean profileSpecific, ConfigData configData, int propertySourceIndex,
445-
ConversionService conversionService, ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
443+
static ConfigDataEnvironmentContributor ofUnboundImport(@Nullable ConfigDataLocation location,
444+
@Nullable ConfigDataResource resource, boolean profileSpecific, ConfigData configData,
445+
int propertySourceIndex, ConversionService conversionService,
446+
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
446447
PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
447448
ConfigData.Options options = configData.getOptions(propertySource);
448449
options = environmentUpdateListener.onConfigDataOptions(configData, propertySource, options);

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static void applyTo(ConfigurableEnvironment environment, @Nullable Resour
160160
* {@link ConfigDataEnvironmentUpdateListener} that can be used to track
161161
* {@link Environment} updates.
162162
*/
163-
public static void applyTo(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
163+
public static void applyTo(ConfigurableEnvironment environment, @Nullable ResourceLoader resourceLoader,
164164
@Nullable ConfigurableBootstrapContext bootstrapContext, Collection<String> additionalProfiles,
165165
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
166166
DeferredLogFactory logFactory = Supplier::get;

core/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataProperties.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.boot.context.properties.bind.Binder;
2828
import org.springframework.boot.context.properties.bind.Name;
2929
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
30+
import org.springframework.util.Assert;
3031
import org.springframework.util.ObjectUtils;
3132

3233
/**
@@ -99,14 +100,14 @@ static class Activate {
99100

100101
private final @Nullable CloudPlatform onCloudPlatform;
101102

102-
private final String[] onProfile;
103+
private final String @Nullable [] onProfile;
103104

104105
/**
105106
* Create a new {@link Activate} instance.
106107
* @param onCloudPlatform the cloud platform required for activation
107108
* @param onProfile the profile expression required for activation
108109
*/
109-
Activate(@Nullable CloudPlatform onCloudPlatform, String[] onProfile) {
110+
Activate(@Nullable CloudPlatform onCloudPlatform, String @Nullable [] onProfile) {
110111
this.onProfile = onProfile;
111112
this.onCloudPlatform = onCloudPlatform;
112113
}
@@ -137,6 +138,7 @@ private boolean isActive(@Nullable Profiles profiles) {
137138
}
138139

139140
private boolean matchesActiveProfiles(Predicate<String> activeProfiles) {
141+
Assert.state(this.onProfile != null, "'this.onProfile' must not be null");
140142
return org.springframework.core.env.Profiles.of(this.onProfile).matches(activeProfiles);
141143
}
142144

0 commit comments

Comments
 (0)