diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/MultipartConfigFactory.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/MultipartConfigFactory.java index cfe76fe92ee..f223bc82641 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/MultipartConfigFactory.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/MultipartConfigFactory.java @@ -17,6 +17,7 @@ package org.springframework.boot.servlet; import jakarta.servlet.MultipartConfigElement; +import org.jspecify.annotations.Nullable; import org.springframework.util.unit.DataSize; @@ -28,19 +29,19 @@ import org.springframework.util.unit.DataSize; */ public class MultipartConfigFactory { - private String location; + private @Nullable String location; - private DataSize maxFileSize; + private @Nullable DataSize maxFileSize; - private DataSize maxRequestSize; + private @Nullable DataSize maxRequestSize; - private DataSize fileSizeThreshold; + private @Nullable DataSize fileSizeThreshold; /** * Sets the directory location where files will be stored. * @param location the location */ - public void setLocation(String location) { + public void setLocation(@Nullable String location) { this.location = location; } @@ -48,7 +49,7 @@ public class MultipartConfigFactory { * Sets the maximum {@link DataSize size} allowed for uploaded files. * @param maxFileSize the maximum file size */ - public void setMaxFileSize(DataSize maxFileSize) { + public void setMaxFileSize(@Nullable DataSize maxFileSize) { this.maxFileSize = maxFileSize; } @@ -56,7 +57,7 @@ public class MultipartConfigFactory { * Sets the maximum {@link DataSize} allowed for multipart/form-data requests. * @param maxRequestSize the maximum request size */ - public void setMaxRequestSize(DataSize maxRequestSize) { + public void setMaxRequestSize(@Nullable DataSize maxRequestSize) { this.maxRequestSize = maxRequestSize; } @@ -64,7 +65,7 @@ public class MultipartConfigFactory { * Sets the {@link DataSize size} threshold after which files will be written to disk. * @param fileSizeThreshold the file size threshold */ - public void setFileSizeThreshold(DataSize fileSizeThreshold) { + public void setFileSizeThreshold(@Nullable DataSize fileSizeThreshold) { this.fileSizeThreshold = fileSizeThreshold; } @@ -87,7 +88,7 @@ public class MultipartConfigFactory { * @param defaultValue the default value if the size is {@code null} or negative * @return the amount of bytes to use */ - private long convertToBytes(DataSize size, int defaultValue) { + private long convertToBytes(@Nullable DataSize size, int defaultValue) { if (size != null && !size.isNegative()) { return size.toBytes(); } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/HttpExchangesFilter.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/HttpExchangesFilter.java index 8b82c9938e4..200619362f9 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/HttpExchangesFilter.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/HttpExchangesFilter.java @@ -27,6 +27,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.boot.actuate.web.exchanges.HttpExchange; import org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository; @@ -106,7 +107,7 @@ public class HttpExchangesFilter extends OncePerRequestFilter implements Ordered } } - private String getSessionId(HttpServletRequest request) { + private @Nullable String getSessionId(HttpServletRequest request) { HttpSession session = request.getSession(false); return (session != null) ? session.getId() : null; } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/package-info.java index dce4f92c9ec..cd8ad92965a 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/exchanges/package-info.java @@ -19,4 +19,7 @@ * * @see org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository */ +@NullMarked package org.springframework.boot.servlet.actuate.exchanges; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/FiltersMappingDescriptionProvider.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/FiltersMappingDescriptionProvider.java index 5e6cb27cf91..78b8cf63b41 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/FiltersMappingDescriptionProvider.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/FiltersMappingDescriptionProvider.java @@ -21,6 +21,7 @@ import java.util.List; import jakarta.servlet.Filter; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.RuntimeHints; @@ -29,6 +30,7 @@ import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; import org.springframework.boot.servlet.actuate.mappings.FiltersMappingDescriptionProvider.FiltersMappingDescriptionProviderRuntimeHints; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; /** @@ -44,8 +46,9 @@ public class FiltersMappingDescriptionProvider implements MappingDescriptionProv @Override public List describeMappings(ApplicationContext context) { if (context instanceof WebApplicationContext webApplicationContext) { - return webApplicationContext.getServletContext() - .getFilterRegistrations() + ServletContext servletContext = webApplicationContext.getServletContext(); + Assert.state(servletContext != null, "'servletContext' must not be null"); + return servletContext.getFilterRegistrations() .values() .stream() .map(FilterRegistrationMappingDescription::new) @@ -64,7 +67,7 @@ public class FiltersMappingDescriptionProvider implements MappingDescriptionProv private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar(); @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { this.bindingRegistrar.registerReflectionHints(hints.reflection(), FilterRegistrationMappingDescription.class); } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/ServletsMappingDescriptionProvider.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/ServletsMappingDescriptionProvider.java index 1fa32fe3051..f079314e5aa 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/ServletsMappingDescriptionProvider.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/ServletsMappingDescriptionProvider.java @@ -21,6 +21,7 @@ import java.util.List; import jakarta.servlet.Servlet; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.RuntimeHints; @@ -29,6 +30,7 @@ import org.springframework.boot.actuate.web.mappings.MappingDescriptionProvider; import org.springframework.boot.servlet.actuate.mappings.ServletsMappingDescriptionProvider.ServletsMappingDescriptionProviderRuntimeHints; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; /** @@ -44,8 +46,9 @@ public class ServletsMappingDescriptionProvider implements MappingDescriptionPro @Override public List describeMappings(ApplicationContext context) { if (context instanceof WebApplicationContext webApplicationContext) { - return webApplicationContext.getServletContext() - .getServletRegistrations() + ServletContext servletContext = webApplicationContext.getServletContext(); + Assert.state(servletContext != null, "'servletContext' must not be null"); + return servletContext.getServletRegistrations() .values() .stream() .map(ServletRegistrationMappingDescription::new) @@ -64,7 +67,7 @@ public class ServletsMappingDescriptionProvider implements MappingDescriptionPro private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar(); @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { this.bindingRegistrar.registerReflectionHints(hints.reflection(), ServletRegistrationMappingDescription.class); } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/package-info.java index 18de59bf640..672a463c7e9 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/actuate/mappings/package-info.java @@ -17,4 +17,7 @@ /** * Actuator servlet request mappings support. */ +@NullMarked package org.springframework.boot.servlet.actuate.mappings; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/MultipartProperties.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/MultipartProperties.java index aecac5dca7f..c67aae023f4 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/MultipartProperties.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/MultipartProperties.java @@ -17,6 +17,7 @@ package org.springframework.boot.servlet.autoconfigure; import jakarta.servlet.MultipartConfigElement; +import org.jspecify.annotations.Nullable; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.PropertyMapper; @@ -57,7 +58,7 @@ public class MultipartProperties { /** * Intermediate location of uploaded files. */ - private String location; + private @Nullable String location; /** * Max file size. @@ -94,11 +95,11 @@ public class MultipartProperties { this.enabled = enabled; } - public String getLocation() { + public @Nullable String getLocation() { return this.location; } - public void setLocation(String location) { + public void setLocation(@Nullable String location) { this.location = location; } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/ServletEncodingProperties.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/ServletEncodingProperties.java index 89c535ab187..4b4705df6ff 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/ServletEncodingProperties.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/ServletEncodingProperties.java @@ -19,6 +19,8 @@ package org.springframework.boot.servlet.autoconfigure; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -45,18 +47,18 @@ public class ServletEncodingProperties { * Whether to force the encoding to the configured charset on HTTP requests and * responses. */ - private Boolean force; + private @Nullable Boolean force; /** * Whether to force the encoding to the configured charset on HTTP requests. Defaults * to true when "force" has not been specified. */ - private Boolean forceRequest; + private @Nullable Boolean forceRequest; /** * Whether to force the encoding to the configured charset on HTTP responses. */ - private Boolean forceResponse; + private @Nullable Boolean forceResponse; public Charset getCharset() { return this.charset; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/package-info.java index 2f7a54b2aa2..f3305768ee9 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/package-info.java @@ -17,4 +17,7 @@ /** * Actuator Servlet support. */ +@NullMarked package org.springframework.boot.servlet.autoconfigure.actuate; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/ServletManagementChildContextConfiguration.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/ServletManagementChildContextConfiguration.java index 7cacf754c07..964c7b6a2d0 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/ServletManagementChildContextConfiguration.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/ServletManagementChildContextConfiguration.java @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.util.Assert; /** * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Servlet web @@ -64,14 +65,16 @@ class ServletManagementChildContextConfiguration { @Bean Filter springSecurityFilterChain(HierarchicalBeanFactory beanFactory) { BeanFactory parent = beanFactory.getParentBeanFactory(); + Assert.state(parent != null, "'parent' must not be null"); return parent.getBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN, Filter.class); } @Bean @ConditionalOnBean(name = "securityFilterChainRegistration", search = SearchStrategy.ANCESTORS) DelegatingFilterProxyRegistrationBean securityFilterChainRegistration(HierarchicalBeanFactory beanFactory) { - return beanFactory.getParentBeanFactory() - .getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class); + BeanFactory parent = beanFactory.getParentBeanFactory(); + Assert.state(parent != null, "'parent' must not be null"); + return parent.getBean("securityFilterChainRegistration", DelegatingFilterProxyRegistrationBean.class); } } diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/package-info.java index a2aaffb0853..14f5cf7fb47 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/actuate/web/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for {@code jakarta.servlet} actuator web concerns. */ +@NullMarked package org.springframework.boot.servlet.autoconfigure.actuate.web; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/package-info.java index 69a68f58580..dec6203432c 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/autoconfigure/package-info.java @@ -18,4 +18,7 @@ * Auto-configuration for application support of the {@code jakarta.servlet} * specification. */ +@NullMarked package org.springframework.boot.servlet.autoconfigure; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/filter/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/filter/package-info.java index c7c2b1ac032..44795abe48d 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/filter/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/filter/package-info.java @@ -17,4 +17,7 @@ /** * Spring Boot specific {@link jakarta.servlet.Filter} implementations. */ +@NullMarked package org.springframework.boot.servlet.filter; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/package-info.java b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/package-info.java index 2ab8c421218..640247b0643 100644 --- a/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/package-info.java +++ b/module/spring-boot-servlet/src/main/java/org/springframework/boot/servlet/package-info.java @@ -17,4 +17,7 @@ /** * Application support for the {@code jakarta.servlet} specification. */ +@NullMarked package org.springframework.boot.servlet; + +import org.jspecify.annotations.NullMarked;