mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-07 09:49:39 +00:00
Add nullability annotations to module/spring-boot-servlet
See gh-46587
This commit is contained in:
+10
-9
@@ -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();
|
||||
}
|
||||
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
+3
@@ -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;
|
||||
|
||||
+6
-3
@@ -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<FilterRegistrationMappingDescription> 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);
|
||||
}
|
||||
|
||||
+6
-3
@@ -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<ServletRegistrationMappingDescription> 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);
|
||||
}
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Actuator servlet request mappings support.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.servlet.actuate.mappings;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+4
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -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;
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Actuator Servlet support.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.servlet.autoconfigure.actuate;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+5
-2
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
@@ -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;
|
||||
|
||||
+3
@@ -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;
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Spring Boot specific {@link jakarta.servlet.Filter} implementations.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.servlet.filter;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
+3
@@ -17,4 +17,7 @@
|
||||
/**
|
||||
* Application support for the {@code jakarta.servlet} specification.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.servlet;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
Reference in New Issue
Block a user