Browse Source

Improve null-safety of core/spring-boot

See gh-46926
pull/47268/head
Moritz Halbritter 3 months ago
parent
commit
aac1845cac
  1. 6
      core/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrar.java
  2. 2
      core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/CachingConfigurationPropertySource.java
  3. 3
      core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationProperty.java
  4. 10
      core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java
  5. 2
      core/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java
  6. 4
      core/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java
  7. 4
      core/spring-boot/src/main/java/org/springframework/boot/json/AbstractJsonParser.java
  8. 4
      core/spring-boot/src/main/java/org/springframework/boot/json/BasicJsonParser.java
  9. 5
      core/spring-boot/src/main/java/org/springframework/boot/json/GsonJsonParser.java
  10. 4
      core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java
  11. 6
      core/spring-boot/src/main/java/org/springframework/boot/json/JsonParser.java
  12. 4
      core/spring-boot/src/main/java/org/springframework/boot/logging/DelegatingLoggingSystemFactory.java
  13. 2
      core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java
  14. 3
      core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/EnclosedInSquareBracketsConverter.java
  15. 2
      core/spring-boot/src/main/java/org/springframework/boot/logging/logback/EnclosedInSquareBracketsConverter.java
  16. 2
      core/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java
  17. 9
      core/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java
  18. 2
      core/spring-boot/src/main/java/org/springframework/boot/origin/OriginLookup.java
  19. 2
      core/spring-boot/src/main/java/org/springframework/boot/ssl/jks/JksSslStoreDetails.java
  20. 14
      core/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStore.java
  21. 4
      core/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreDetails.java
  22. 2
      core/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPid.java
  23. 4
      core/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializer.java

6
core/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrar.java

@ -20,6 +20,8 @@ import java.util.Arrays;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@ -50,9 +52,9 @@ class ConfigurationPropertiesScanRegistrar implements ImportBeanDefinitionRegist
private final Environment environment; private final Environment environment;
private final ResourceLoader resourceLoader; private final @Nullable ResourceLoader resourceLoader;
ConfigurationPropertiesScanRegistrar(Environment environment, ResourceLoader resourceLoader) { ConfigurationPropertiesScanRegistrar(Environment environment, @Nullable ResourceLoader resourceLoader) {
this.environment = environment; this.environment = environment;
this.resourceLoader = resourceLoader; this.resourceLoader = resourceLoader;
} }

2
core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/CachingConfigurationPropertySource.java

@ -38,7 +38,7 @@ interface CachingConfigurationPropertySource {
* @return a {@link ConfigurationPropertyCaching} instance or {@code null} if the * @return a {@link ConfigurationPropertyCaching} instance or {@code null} if the
* source does not support caching. * source does not support caching.
*/ */
static @Nullable ConfigurationPropertyCaching find(ConfigurationPropertySource source) { static @Nullable ConfigurationPropertyCaching find(@Nullable ConfigurationPropertySource source) {
if (source instanceof CachingConfigurationPropertySource cachingSource) { if (source instanceof CachingConfigurationPropertySource cachingSource) {
return cachingSource.getCaching(); return cachingSource.getCaching();
} }

3
core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationProperty.java

@ -22,6 +22,7 @@ import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginProvider; import org.springframework.boot.origin.OriginProvider;
import org.springframework.boot.origin.OriginTrackedValue; import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Contract;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -124,6 +125,7 @@ public final class ConfigurationProperty implements OriginProvider, Comparable<C
return this.name.compareTo(other.name); return this.name.compareTo(other.name);
} }
@Contract("_, !null -> !null")
static @Nullable ConfigurationProperty of(ConfigurationPropertyName name, @Nullable OriginTrackedValue value) { static @Nullable ConfigurationProperty of(ConfigurationPropertyName name, @Nullable OriginTrackedValue value) {
if (value == null) { if (value == null) {
return null; return null;
@ -131,6 +133,7 @@ public final class ConfigurationProperty implements OriginProvider, Comparable<C
return new ConfigurationProperty(name, value.getValue(), value.getOrigin()); return new ConfigurationProperty(name, value.getValue(), value.getOrigin());
} }
@Contract("_, _, !null, _ -> !null")
static @Nullable ConfigurationProperty of(@Nullable ConfigurationPropertySource source, static @Nullable ConfigurationProperty of(@Nullable ConfigurationPropertySource source,
ConfigurationPropertyName name, @Nullable Object value, @Nullable Origin origin) { ConfigurationPropertyName name, @Nullable Object value, @Nullable Origin origin) {
if (value == null) { if (value == null) {

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

@ -210,7 +210,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
* @return a new {@link ConfigurationPropertyName} * @return a new {@link ConfigurationPropertyName}
* @throws InvalidConfigurationPropertyNameException if the result is not valid * @throws InvalidConfigurationPropertyNameException if the result is not valid
*/ */
public ConfigurationPropertyName append(String suffix) { public ConfigurationPropertyName append(@Nullable String suffix) {
if (!StringUtils.hasLength(suffix)) { if (!StringUtils.hasLength(suffix)) {
return this; return this;
} }
@ -625,7 +625,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
* @param name the name to test * @param name the name to test
* @return {@code true} if the name is valid * @return {@code true} if the name is valid
*/ */
public static boolean isValid(CharSequence name) { public static boolean isValid(@Nullable CharSequence name) {
return of(name, true) != null; return of(name, true) != null;
} }
@ -636,7 +636,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
* @throws InvalidConfigurationPropertyNameException if the name is not valid * @throws InvalidConfigurationPropertyNameException if the name is not valid
*/ */
@SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1232 @SuppressWarnings("NullAway") // See https://github.com/uber/NullAway/issues/1232
public static ConfigurationPropertyName of(CharSequence name) { public static ConfigurationPropertyName of(@Nullable CharSequence name) {
return of(name, false); return of(name, false);
} }
@ -647,7 +647,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
* @return a {@link ConfigurationPropertyName} instance * @return a {@link ConfigurationPropertyName} instance
* @since 2.3.1 * @since 2.3.1
*/ */
public static @Nullable ConfigurationPropertyName ofIfValid(CharSequence name) { public static @Nullable ConfigurationPropertyName ofIfValid(@Nullable CharSequence name) {
return of(name, true); return of(name, true);
} }
@ -660,7 +660,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
* {@code returnNullIfInvalid} is {@code false} * {@code returnNullIfInvalid} is {@code false}
*/ */
@Contract("_, false -> !null") @Contract("_, false -> !null")
static @Nullable ConfigurationPropertyName of(CharSequence name, boolean returnNullIfInvalid) { static @Nullable ConfigurationPropertyName of(@Nullable CharSequence name, boolean returnNullIfInvalid) {
Elements elements = elementsOf(name, returnNullIfInvalid, ElementsParser.DEFAULT_CAPACITY); Elements elements = elementsOf(name, returnNullIfInvalid, ElementsParser.DEFAULT_CAPACITY);
return (elements != null) ? new ConfigurationPropertyName(elements) : null; return (elements != null) ? new ConfigurationPropertyName(elements) : null;
} }

2
core/spring-boot/src/main/java/org/springframework/boot/diagnostics/AbstractFailureAnalyzer.java

@ -61,7 +61,7 @@ public abstract class AbstractFailureAnalyzer<T extends Throwable> implements Fa
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected final <E extends Throwable> @Nullable E findCause(Throwable failure, Class<E> type) { protected final <E extends Throwable> @Nullable E findCause(@Nullable Throwable failure, Class<E> type) {
while (failure != null) { while (failure != null) {
if (type.isInstance(failure)) { if (type.isInstance(failure)) {
return (E) failure; return (E) failure;

4
core/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/MutuallyExclusiveConfigurationPropertiesFailureAnalyzer.java

@ -48,9 +48,9 @@ import org.springframework.core.env.PropertySource;
class MutuallyExclusiveConfigurationPropertiesFailureAnalyzer class MutuallyExclusiveConfigurationPropertiesFailureAnalyzer
extends AbstractFailureAnalyzer<MutuallyExclusiveConfigurationPropertiesException> { extends AbstractFailureAnalyzer<MutuallyExclusiveConfigurationPropertiesException> {
private final ConfigurableEnvironment environment; private final @Nullable ConfigurableEnvironment environment;
MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(Environment environment) { MutuallyExclusiveConfigurationPropertiesFailureAnalyzer(@Nullable Environment environment) {
this.environment = (ConfigurableEnvironment) environment; this.environment = (ConfigurableEnvironment) environment;
} }

4
core/spring-boot/src/main/java/org/springframework/boot/json/AbstractJsonParser.java

@ -34,11 +34,11 @@ import org.springframework.util.ReflectionUtils;
*/ */
public abstract class AbstractJsonParser implements JsonParser { public abstract class AbstractJsonParser implements JsonParser {
protected final Map<String, Object> parseMap(String json, Function<String, Map<String, Object>> parser) { protected final Map<String, Object> parseMap(@Nullable String json, Function<String, Map<String, Object>> parser) {
return trimParse(json, "{", parser); return trimParse(json, "{", parser);
} }
protected final List<Object> parseList(String json, Function<String, List<Object>> parser) { protected final List<Object> parseList(@Nullable String json, Function<String, List<Object>> parser) {
return trimParse(json, "[", parser); return trimParse(json, "[", parser);
} }

4
core/spring-boot/src/main/java/org/springframework/boot/json/BasicJsonParser.java

@ -44,12 +44,12 @@ public class BasicJsonParser extends AbstractJsonParser {
private static final int MAX_DEPTH = 1000; private static final int MAX_DEPTH = 1000;
@Override @Override
public Map<String, Object> parseMap(String json) { public Map<String, Object> parseMap(@Nullable String json) {
return tryParse(() -> parseMap(json, (jsonToParse) -> parseMapInternal(0, jsonToParse)), Exception.class); return tryParse(() -> parseMap(json, (jsonToParse) -> parseMapInternal(0, jsonToParse)), Exception.class);
} }
@Override @Override
public List<Object> parseList(String json) { public List<Object> parseList(@Nullable String json) {
return tryParse(() -> parseList(json, (jsonToParse) -> parseListInternal(0, jsonToParse)), Exception.class); return tryParse(() -> parseList(json, (jsonToParse) -> parseListInternal(0, jsonToParse)), Exception.class);
} }

5
core/spring-boot/src/main/java/org/springframework/boot/json/GsonJsonParser.java

@ -22,6 +22,7 @@ import java.util.Map;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.jspecify.annotations.Nullable;
/** /**
* Thin wrapper to adapt {@link Gson} to a {@link JsonParser}. * Thin wrapper to adapt {@link Gson} to a {@link JsonParser}.
@ -40,13 +41,13 @@ public class GsonJsonParser extends AbstractJsonParser {
private final Gson gson = new GsonBuilder().create(); private final Gson gson = new GsonBuilder().create();
@Override @Override
public Map<String, Object> parseMap(String json) { public Map<String, Object> parseMap(@Nullable String json) {
return tryParse(() -> parseMap(json, (trimmed) -> this.gson.fromJson(trimmed, MAP_TYPE.getType())), return tryParse(() -> parseMap(json, (trimmed) -> this.gson.fromJson(trimmed, MAP_TYPE.getType())),
Exception.class); Exception.class);
} }
@Override @Override
public List<Object> parseList(String json) { public List<Object> parseList(@Nullable String json) {
return tryParse(() -> parseList(json, (trimmed) -> this.gson.fromJson(trimmed, LIST_TYPE.getType())), return tryParse(() -> parseList(json, (trimmed) -> this.gson.fromJson(trimmed, LIST_TYPE.getType())),
Exception.class); Exception.class);
} }

4
core/spring-boot/src/main/java/org/springframework/boot/json/JacksonJsonParser.java

@ -53,12 +53,12 @@ public class JacksonJsonParser extends AbstractJsonParser {
} }
@Override @Override
public Map<String, Object> parseMap(String json) { public Map<String, Object> parseMap(@Nullable String json) {
return tryParse(() -> getObjectMapper().readValue(json, MAP_TYPE), Exception.class); return tryParse(() -> getObjectMapper().readValue(json, MAP_TYPE), Exception.class);
} }
@Override @Override
public List<Object> parseList(String json) { public List<Object> parseList(@Nullable String json) {
return tryParse(() -> getObjectMapper().readValue(json, LIST_TYPE), Exception.class); return tryParse(() -> getObjectMapper().readValue(json, LIST_TYPE), Exception.class);
} }

6
core/spring-boot/src/main/java/org/springframework/boot/json/JsonParser.java

@ -19,6 +19,8 @@ package org.springframework.boot.json;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jspecify.annotations.Nullable;
/** /**
* Parser that can read JSON formatted strings into {@link Map}s or {@link List}s. * Parser that can read JSON formatted strings into {@link Map}s or {@link List}s.
* *
@ -37,7 +39,7 @@ public interface JsonParser {
* @return the parsed JSON as a map * @return the parsed JSON as a map
* @throws JsonParseException if the JSON cannot be parsed * @throws JsonParseException if the JSON cannot be parsed
*/ */
Map<String, Object> parseMap(String json) throws JsonParseException; Map<String, Object> parseMap(@Nullable String json) throws JsonParseException;
/** /**
* Parse the specified JSON string into a List. * Parse the specified JSON string into a List.
@ -45,6 +47,6 @@ public interface JsonParser {
* @return the parsed JSON as a list * @return the parsed JSON as a list
* @throws JsonParseException if the JSON cannot be parsed * @throws JsonParseException if the JSON cannot be parsed
*/ */
List<Object> parseList(String json) throws JsonParseException; List<Object> parseList(@Nullable String json) throws JsonParseException;
} }

4
core/spring-boot/src/main/java/org/springframework/boot/logging/DelegatingLoggingSystemFactory.java

@ -28,13 +28,13 @@ import org.jspecify.annotations.Nullable;
*/ */
class DelegatingLoggingSystemFactory implements LoggingSystemFactory { class DelegatingLoggingSystemFactory implements LoggingSystemFactory {
private final @Nullable Function<ClassLoader, List<LoggingSystemFactory>> delegates; private final @Nullable Function<ClassLoader, @Nullable List<LoggingSystemFactory>> delegates;
/** /**
* Create a new {@link DelegatingLoggingSystemFactory} instance. * Create a new {@link DelegatingLoggingSystemFactory} instance.
* @param delegates a function that provides the delegates * @param delegates a function that provides the delegates
*/ */
DelegatingLoggingSystemFactory(@Nullable Function<ClassLoader, List<LoggingSystemFactory>> delegates) { DelegatingLoggingSystemFactory(@Nullable Function<ClassLoader, @Nullable List<LoggingSystemFactory>> delegates) {
this.delegates = delegates; this.delegates = delegates;
} }

2
core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java

@ -120,7 +120,7 @@ public final class ColorConverter extends LogEventPatternConverter {
* @param options the options * @param options the options
* @return a new instance, or {@code null} if the options are invalid * @return a new instance, or {@code null} if the options are invalid
*/ */
public static @Nullable ColorConverter newInstance(Configuration config, @Nullable String[] options) { public static @Nullable ColorConverter newInstance(@Nullable Configuration config, @Nullable String[] options) {
if (options.length < 1) { if (options.length < 1) {
LOGGER.error("Incorrect number of options on style. Expected at least 1, received {}", options.length); LOGGER.error("Incorrect number of options on style. Expected at least 1, received {}", options.length);
return null; return null;

3
core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/EnclosedInSquareBracketsConverter.java

@ -67,7 +67,8 @@ public final class EnclosedInSquareBracketsConverter extends LogEventPatternConv
* @param options the options * @param options the options
* @return a new instance, or {@code null} if the options are invalid * @return a new instance, or {@code null} if the options are invalid
*/ */
public static @Nullable EnclosedInSquareBracketsConverter newInstance(Configuration config, String[] options) { public static @Nullable EnclosedInSquareBracketsConverter newInstance(@Nullable Configuration config,
String[] options) {
if (options.length < 1) { if (options.length < 1) {
LOGGER.error("Incorrect number of options on style. Expected at least 1, received {}", options.length); LOGGER.error("Incorrect number of options on style. Expected at least 1, received {}", options.length);
return null; return null;

2
core/spring-boot/src/main/java/org/springframework/boot/logging/logback/EnclosedInSquareBracketsConverter.java

@ -32,7 +32,7 @@ import org.springframework.util.StringUtils;
public class EnclosedInSquareBracketsConverter extends CompositeConverter<ILoggingEvent> { public class EnclosedInSquareBracketsConverter extends CompositeConverter<ILoggingEvent> {
@Override @Override
protected String transform(ILoggingEvent event, String in) { protected String transform(ILoggingEvent event, @Nullable String in) {
in = (!StringUtils.hasLength(in)) ? resolveFromFirstOption(event) : in; in = (!StringUtils.hasLength(in)) ? resolveFromFirstOption(event) : in;
return (!StringUtils.hasLength(in)) ? "" : "[%s] ".formatted(in); return (!StringUtils.hasLength(in)) ? "" : "[%s] ".formatted(in);
} }

2
core/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystemProperties.java

@ -68,7 +68,7 @@ public class LogbackLoggingSystemProperties extends LoggingSystemProperties {
* @since 3.2.0 * @since 3.2.0
*/ */
public LogbackLoggingSystemProperties(Environment environment, public LogbackLoggingSystemProperties(Environment environment,
Function<@Nullable String, @Nullable String> defaultValueResolver, @Nullable Function<@Nullable String, @Nullable String> defaultValueResolver,
@Nullable BiConsumer<String, @Nullable String> setter) { @Nullable BiConsumer<String, @Nullable String> setter) {
super(environment, defaultValueResolver, setter); super(environment, defaultValueResolver, setter);
} }

9
core/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLoggingJsonProperties.java

@ -56,11 +56,11 @@ import org.springframework.util.Assert;
* @author Yanming Zhou * @author Yanming Zhou
*/ */
record StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename, record StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename,
Map<String, String> add, StackTrace stackTrace, Context context, Map<String, String> add, @Nullable StackTrace stackTrace, @Nullable Context context,
Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) { Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) {
StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename, StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude, Map<String, String> rename,
Map<String, String> add, StackTrace stackTrace, Context context, Map<String, String> add, @Nullable StackTrace stackTrace, @Nullable Context context,
@Nullable Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) { @Nullable Set<Class<? extends StructuredLoggingJsonMembersCustomizer<?>>> customizer) {
this.include = include; this.include = include;
this.exclude = exclude; this.exclude = exclude;
@ -98,8 +98,9 @@ record StructuredLoggingJsonProperties(Set<String> include, Set<String> exclude,
* @param includeCommonFrames whether common frames should be included * @param includeCommonFrames whether common frames should be included
* @param includeHashes whether stack trace hashes should be included * @param includeHashes whether stack trace hashes should be included
*/ */
record StackTrace(@Nullable String printer, Root root, Integer maxLength, Integer maxThrowableDepth, record StackTrace(@Nullable String printer, @Nullable Root root, @Nullable Integer maxLength,
Boolean includeCommonFrames, Boolean includeHashes) { @Nullable Integer maxThrowableDepth, @Nullable Boolean includeCommonFrames,
@Nullable Boolean includeHashes) {
@Nullable StackTracePrinter createPrinter() { @Nullable StackTracePrinter createPrinter() {
String name = sanitizePrinter(); String name = sanitizePrinter();

2
core/spring-boot/src/main/java/org/springframework/boot/origin/OriginLookup.java

@ -47,7 +47,7 @@ public interface OriginLookup<K> {
* @return an {@link Origin} or {@code null} * @return an {@link Origin} or {@code null}
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static <K> @Nullable Origin getOrigin(Object source, K key) { static <K> @Nullable Origin getOrigin(@Nullable Object source, K key) {
if (!(source instanceof OriginLookup)) { if (!(source instanceof OriginLookup)) {
return null; return null;
} }

2
core/spring-boot/src/main/java/org/springframework/boot/ssl/jks/JksSslStoreDetails.java

@ -61,7 +61,7 @@ public record JksSslStoreDetails(@Nullable String type, @Nullable String provide
* @param location the location * @param location the location
* @return a new {@link JksSslStoreDetails} instance. * @return a new {@link JksSslStoreDetails} instance.
*/ */
public static JksSslStoreDetails forLocation(String location) { public static JksSslStoreDetails forLocation(@Nullable String location) {
return new JksSslStoreDetails(null, null, location, null); return new JksSslStoreDetails(null, null, location, null);
} }

14
core/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStore.java

@ -78,7 +78,9 @@ public interface PemSslStore {
* @return a new {@link PemSslStore} instance * @return a new {@link PemSslStore} instance
*/ */
default PemSslStore withAlias(@Nullable String alias) { default PemSslStore withAlias(@Nullable String alias) {
return of(type(), alias, password(), certificates(), privateKey()); List<X509Certificate> certificates = certificates();
Assert.notNull(certificates, "'certificates' must not be null");
return of(type(), alias, password(), certificates, privateKey());
} }
/** /**
@ -87,7 +89,9 @@ public interface PemSslStore {
* @return a new {@link PemSslStore} instance * @return a new {@link PemSslStore} instance
*/ */
default PemSslStore withPassword(@Nullable String password) { default PemSslStore withPassword(@Nullable String password) {
return of(type(), alias(), password, certificates(), privateKey()); List<X509Certificate> certificates = certificates();
Assert.notNull(certificates, "'certificates' must not be null");
return of(type(), alias(), password, certificates, privateKey());
} }
/** /**
@ -123,7 +127,7 @@ public interface PemSslStore {
* @param privateKey the private key * @param privateKey the private key
* @return a new {@link PemSslStore} instance * @return a new {@link PemSslStore} instance
*/ */
static PemSslStore of(String type, List<X509Certificate> certificates, PrivateKey privateKey) { static PemSslStore of(@Nullable String type, List<X509Certificate> certificates, @Nullable PrivateKey privateKey) {
return of(type, null, null, certificates, privateKey); return of(type, null, null, certificates, privateKey);
} }
@ -134,7 +138,7 @@ public interface PemSslStore {
* @param privateKey the private key * @param privateKey the private key
* @return a new {@link PemSslStore} instance * @return a new {@link PemSslStore} instance
*/ */
static PemSslStore of(List<X509Certificate> certificates, PrivateKey privateKey) { static PemSslStore of(List<X509Certificate> certificates, @Nullable PrivateKey privateKey) {
return of(null, null, null, certificates, privateKey); return of(null, null, null, certificates, privateKey);
} }
@ -151,7 +155,7 @@ public interface PemSslStore {
* @return a new {@link PemSslStore} instance * @return a new {@link PemSslStore} instance
*/ */
static PemSslStore of(@Nullable String type, @Nullable String alias, @Nullable String password, static PemSslStore of(@Nullable String type, @Nullable String alias, @Nullable String password,
@Nullable List<X509Certificate> certificates, @Nullable PrivateKey privateKey) { List<X509Certificate> certificates, @Nullable PrivateKey privateKey) {
Assert.notEmpty(certificates, "'certificates' must not be empty"); Assert.notEmpty(certificates, "'certificates' must not be empty");
return new PemSslStore() { return new PemSslStore() {

4
core/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemSslStoreDetails.java

@ -151,7 +151,7 @@ public record PemSslStoreDetails(@Nullable String type, @Nullable String alias,
* reference to the resource to load) * reference to the resource to load)
* @return a new {@link PemSslStoreDetails} instance. * @return a new {@link PemSslStoreDetails} instance.
*/ */
public static PemSslStoreDetails forCertificate(String certificate) { public static PemSslStoreDetails forCertificate(@Nullable String certificate) {
return forCertificates(certificate); return forCertificates(certificate);
} }
@ -163,7 +163,7 @@ public record PemSslStoreDetails(@Nullable String type, @Nullable String alias,
* @return a new {@link PemSslStoreDetails} instance. * @return a new {@link PemSslStoreDetails} instance.
* @since 3.2.0 * @since 3.2.0
*/ */
public static PemSslStoreDetails forCertificates(String certificates) { public static PemSslStoreDetails forCertificates(@Nullable String certificates) {
return new PemSslStoreDetails(null, certificates, null); return new PemSslStoreDetails(null, certificates, null);
} }

2
core/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPid.java

@ -46,7 +46,7 @@ public class ApplicationPid {
this.pid = currentProcessPid(); this.pid = currentProcessPid();
} }
protected ApplicationPid(Long pid) { protected ApplicationPid(@Nullable Long pid) {
this.pid = pid; this.pid = pid;
} }

4
core/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializer.java

@ -151,7 +151,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
} }
} }
protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) { protected @Nullable WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
SpringApplicationBuilder builder = createSpringApplicationBuilder(); SpringApplicationBuilder builder = createSpringApplicationBuilder();
builder.main(getClass()); builder.main(getClass());
ApplicationContext parent = getExistingRootWebApplicationContext(servletContext); ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
@ -201,7 +201,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
* @param application the application to run * @param application the application to run
* @return the {@link WebApplicationContext} * @return the {@link WebApplicationContext}
*/ */
protected WebApplicationContext run(SpringApplication application) { protected @Nullable WebApplicationContext run(SpringApplication application) {
return (WebApplicationContext) application.run(); return (WebApplicationContext) application.run();
} }

Loading…
Cancel
Save