Improve null-safety of core/spring-boot

See gh-46926
This commit is contained in:
Moritz Halbritter 2025-09-11 15:06:48 +02:00
parent a6b4400de7
commit 009bd441f6
8 changed files with 14 additions and 11 deletions

View File

@ -44,7 +44,7 @@ class ApplicationInfoPropertySource extends MapPropertySource implements OriginL
super(NAME, getProperties(readVersion(mainClass)));
}
ApplicationInfoPropertySource(String applicationVersion) {
ApplicationInfoPropertySource(@Nullable String applicationVersion) {
super(NAME, getProperties(applicationVersion));
}

View File

@ -69,7 +69,7 @@ public class DefaultPropertiesPropertySource extends MapPropertySource {
* @param action the action used to consume the
* {@link DefaultPropertiesPropertySource}
*/
public static void ifNotEmpty(Map<String, Object> source,
public static void ifNotEmpty(@Nullable Map<String, Object> source,
@Nullable Consumer<DefaultPropertiesPropertySource> action) {
if (!CollectionUtils.isEmpty(source) && action != null) {
action.accept(new DefaultPropertiesPropertySource(source));

View File

@ -155,7 +155,7 @@ public class ResourceBanner implements Banner {
return environment.getProperty("spring.application.version");
}
protected String getBootVersion() {
protected @Nullable String getBootVersion() {
return SpringBootVersion.getVersion();
}

View File

@ -88,7 +88,7 @@ public abstract class Configurations {
* @since 3.4.0
*/
protected Configurations(@Nullable UnaryOperator<Collection<Class<?>>> sorter, Collection<Class<?>> classes,
Function<Class<?>, String> beanNameGenerator) {
@Nullable Function<Class<?>, String> beanNameGenerator) {
Assert.notNull(classes, "'classes' must not be null");
this.sorter = (sorter != null) ? sorter : UnaryOperator.identity();
Collection<Class<?>> sorted = this.sorter.apply(classes);

View File

@ -52,7 +52,7 @@ class ConfigDataActivationContext {
* @param cloudPlatform the cloud platform
* @param profiles the profiles
*/
ConfigDataActivationContext(@Nullable CloudPlatform cloudPlatform, Profiles profiles) {
ConfigDataActivationContext(@Nullable CloudPlatform cloudPlatform, @Nullable Profiles profiles) {
this.cloudPlatform = cloudPlatform;
this.profiles = profiles;
}

View File

@ -440,9 +440,10 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
* @param environmentUpdateListener the environment update listener
* @return a new {@link ConfigDataEnvironmentContributor} instance
*/
static ConfigDataEnvironmentContributor ofUnboundImport(ConfigDataLocation location, ConfigDataResource resource,
boolean profileSpecific, ConfigData configData, int propertySourceIndex,
ConversionService conversionService, ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
static ConfigDataEnvironmentContributor ofUnboundImport(@Nullable ConfigDataLocation location,
@Nullable ConfigDataResource resource, boolean profileSpecific, ConfigData configData,
int propertySourceIndex, ConversionService conversionService,
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
ConfigData.Options options = configData.getOptions(propertySource);
options = environmentUpdateListener.onConfigDataOptions(configData, propertySource, options);

View File

@ -160,7 +160,7 @@ public class ConfigDataEnvironmentPostProcessor implements EnvironmentPostProces
* {@link ConfigDataEnvironmentUpdateListener} that can be used to track
* {@link Environment} updates.
*/
public static void applyTo(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
public static void applyTo(ConfigurableEnvironment environment, @Nullable ResourceLoader resourceLoader,
@Nullable ConfigurableBootstrapContext bootstrapContext, Collection<String> additionalProfiles,
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
DeferredLogFactory logFactory = Supplier::get;

View File

@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.bind.Name;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
@ -99,14 +100,14 @@ class ConfigDataProperties {
private final @Nullable CloudPlatform onCloudPlatform;
private final String[] onProfile;
private final String @Nullable [] onProfile;
/**
* Create a new {@link Activate} instance.
* @param onCloudPlatform the cloud platform required for activation
* @param onProfile the profile expression required for activation
*/
Activate(@Nullable CloudPlatform onCloudPlatform, String[] onProfile) {
Activate(@Nullable CloudPlatform onCloudPlatform, String @Nullable [] onProfile) {
this.onProfile = onProfile;
this.onCloudPlatform = onCloudPlatform;
}
@ -137,6 +138,7 @@ class ConfigDataProperties {
}
private boolean matchesActiveProfiles(Predicate<String> activeProfiles) {
Assert.state(this.onProfile != null, "'this.onProfile' must not be null");
return org.springframework.core.env.Profiles.of(this.onProfile).matches(activeProfiles);
}