Refine null-safety in the spring-web module
Closes gh-34162
This commit is contained in:
@@ -62,7 +62,7 @@ abstract class AbstractStreamingClientHttpRequest extends AbstractClientHttpRequ
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
protected final ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
|
||||
if (this.body == null && this.bodyStream != null) {
|
||||
this.body = outputStream -> this.bodyStream.writeTo(outputStream);
|
||||
|
||||
@@ -94,7 +94,6 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
||||
CompletableFuture<HttpResponse<InputStream>> responseFuture = null;
|
||||
try {
|
||||
@@ -133,7 +132,8 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
throw ioEx;
|
||||
}
|
||||
else {
|
||||
throw new IOException(cause.getMessage(), cause);
|
||||
String message = (cause == null ? null : cause.getMessage());
|
||||
throw (message == null ? new IOException(cause) : new IOException(message, cause));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ class JettyClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
||||
if (!headers.isEmpty()) {
|
||||
this.request.headers(httpFields -> {
|
||||
@@ -118,7 +117,8 @@ class JettyClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
throw ioEx;
|
||||
}
|
||||
else {
|
||||
throw new IOException(cause.getMessage(), cause);
|
||||
String message = (cause == null ? null : cause.getMessage());
|
||||
throw (message == null ? new IOException(cause) : new IOException(message, cause));
|
||||
}
|
||||
}
|
||||
catch (TimeoutException ex) {
|
||||
|
||||
@@ -135,7 +135,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private @Nullable Object buildEvent(List<String> lines, ResolvableType valueType, boolean shouldWrap,
|
||||
Map<String, Object> hints) {
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.springframework.http.HttpHeaders;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.3
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
final class MultipartParser extends BaseSubscriber<DataBuffer> {
|
||||
|
||||
private static final byte CR = '\r';
|
||||
@@ -117,12 +116,14 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
protected void hookOnNext(DataBuffer value) {
|
||||
this.requestOutstanding.set(false);
|
||||
this.state.get().onNext(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
protected void hookOnComplete() {
|
||||
this.state.get().onComplete();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ import org.springframework.util.FastByteArrayOutputStream;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.3
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
final class PartGenerator extends BaseSubscriber<MultipartParser.Token> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PartGenerator.class);
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Not null assertion performed in StreamUtils#copyRange
|
||||
private void writeResourceRegionCollection(Collection<ResourceRegion> resourceRegions,
|
||||
HttpOutputMessage outputMessage) throws IOException {
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ import org.springframework.util.Assert;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.util.Assert;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled to the {@link Subscriber}
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public abstract class AbstractListenerWriteFlushProcessor<T> implements Processor<Publisher<? extends T>, Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.StringUtils;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled to the {@link Subscriber}
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public abstract class AbstractListenerWriteProcessor<T> implements Processor<T, Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -159,7 +159,7 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private static HttpHeaders initHeaders(HttpHeaders headerValues, HttpServletRequest request) {
|
||||
|
||||
HttpHeaders headers = null;
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.Assert;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
class WriteResultPublisher implements Publisher<Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -243,7 +243,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||
* {@link RestClientResponseException#setBodyConvertFunction(Function)}.
|
||||
* @since 6.0
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
protected Function<ResolvableType, ?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) {
|
||||
Assert.state(!CollectionUtils.isEmpty(this.messageConverters), "Expected message converters");
|
||||
return resolvableType -> {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||
* @param previousRequest the existing request from the last dispatch
|
||||
* @since 5.3.33
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
StandardServletAsyncWebRequest(HttpServletRequest request, HttpServletResponse response,
|
||||
@Nullable StandardServletAsyncWebRequest previousRequest) {
|
||||
|
||||
@@ -272,7 +272,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public ServletOutputStream getOutputStream() throws IOException {
|
||||
int level = obtainLockOrRaiseException();
|
||||
try {
|
||||
@@ -292,7 +292,7 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public PrintWriter getWriter() throws IOException {
|
||||
int level = obtainLockOrRaiseException();
|
||||
try {
|
||||
|
||||
@@ -298,7 +298,7 @@ public final class WebAsyncManager {
|
||||
* via {@link #getConcurrentResultContext()}
|
||||
* @throws Exception if concurrent processing failed to start
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
public void startCallableProcessing(final WebAsyncTask<?> webAsyncTask, Object... processingContext)
|
||||
throws Exception {
|
||||
|
||||
@@ -419,7 +419,7 @@ public final class WebAsyncManager {
|
||||
* @see #getConcurrentResult()
|
||||
* @see #getConcurrentResultContext()
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
public void startDeferredResultProcessing(
|
||||
final DeferredResult<?> deferredResult, Object... processingContext) throws Exception {
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
|
||||
* @see ServletContextResource
|
||||
* @see jakarta.servlet.ServletContext#getResourcePaths
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
protected void doRetrieveMatchingServletContextResources(
|
||||
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
|
||||
throws IOException {
|
||||
|
||||
@@ -162,7 +162,7 @@ public class CorsConfiguration {
|
||||
/**
|
||||
* Variant of {@link #setAllowedOrigins} for adding one origin at a time.
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
public void addAllowedOrigin(@Nullable String origin) {
|
||||
if (origin == null) {
|
||||
return;
|
||||
@@ -235,7 +235,7 @@ public class CorsConfiguration {
|
||||
* Variant of {@link #setAllowedOriginPatterns} for adding one origin at a time.
|
||||
* @since 5.3
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Lambda
|
||||
public void addAllowedOriginPattern(@Nullable String originPattern) {
|
||||
if (originPattern == null) {
|
||||
return;
|
||||
|
||||
@@ -44,7 +44,8 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
public abstract class AbstractMultipartHttpServletRequest extends HttpServletRequestWrapper
|
||||
implements MultipartHttpServletRequest {
|
||||
|
||||
private @Nullable MultiValueMap<String, MultipartFile> multipartFiles;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private MultiValueMap<String, MultipartFile> multipartFiles;
|
||||
|
||||
|
||||
/**
|
||||
@@ -135,7 +136,6 @@ public abstract class AbstractMultipartHttpServletRequest extends HttpServletReq
|
||||
* lazily initializing it if necessary.
|
||||
* @see #initializeMultipart()
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
protected MultiValueMap<String, MultipartFile> getMultipartFiles() {
|
||||
if (this.multipartFiles == null) {
|
||||
initializeMultipart();
|
||||
|
||||
@@ -45,9 +45,11 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
|
||||
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
private @Nullable Map<String, String[]> multipartParameters;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Map<String, String[]> multipartParameters;
|
||||
|
||||
private @Nullable Map<String, String> multipartParameterContentTypes;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Map<String, String> multipartParameterContentTypes;
|
||||
|
||||
|
||||
/**
|
||||
@@ -164,7 +166,6 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
|
||||
* lazily initializing it if necessary.
|
||||
* @see #initializeMultipart()
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
protected Map<String, String[]> getMultipartParameters() {
|
||||
if (this.multipartParameters == null) {
|
||||
initializeMultipart();
|
||||
@@ -185,7 +186,6 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer
|
||||
* lazily initializing it if necessary.
|
||||
* @see #initializeMultipart()
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
protected Map<String, String> getMultipartParameterContentTypes() {
|
||||
if (this.multipartParameterContentTypes == null) {
|
||||
initializeMultipart();
|
||||
|
||||
@@ -58,7 +58,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpServletRequest {
|
||||
|
||||
private @Nullable Set<String> multipartParameterNames;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Set<String> multipartParameterNames;
|
||||
|
||||
|
||||
/**
|
||||
@@ -138,7 +139,6 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
public Enumeration<String> getParameterNames() {
|
||||
if (this.multipartParameterNames == null) {
|
||||
initializeMultipart();
|
||||
@@ -159,7 +159,6 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
if (this.multipartParameterNames == null) {
|
||||
initializeMultipart();
|
||||
|
||||
@@ -86,7 +86,8 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
||||
|
||||
private WebSessionManager sessionManager = new DefaultWebSessionManager();
|
||||
|
||||
private @Nullable ServerCodecConfigurer codecConfigurer;
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private ServerCodecConfigurer codecConfigurer;
|
||||
|
||||
private LocaleContextResolver localeContextResolver = new AcceptHeaderLocaleContextResolver();
|
||||
|
||||
@@ -149,7 +150,6 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
||||
/**
|
||||
* Return the configured {@link ServerCodecConfigurer}.
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public ServerCodecConfigurer getCodecConfigurer() {
|
||||
if (this.codecConfigurer == null) {
|
||||
setCodecConfigurer(ServerCodecConfigurer.create());
|
||||
|
||||
@@ -189,7 +189,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public String getId() {
|
||||
return this.id.get();
|
||||
}
|
||||
@@ -225,7 +225,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public boolean isStarted() {
|
||||
return this.state.get().equals(State.STARTED) || !getAttributes().isEmpty();
|
||||
}
|
||||
@@ -254,7 +254,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
public Mono<Void> save() {
|
||||
|
||||
checkMaxSessionsLimit();
|
||||
@@ -292,7 +292,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
|
||||
return isExpired(clock.instant());
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private boolean isExpired(Instant now) {
|
||||
if (this.state.get().equals(State.EXPIRED)) {
|
||||
return true;
|
||||
|
||||
@@ -236,7 +236,7 @@ final class HttpServiceMethod {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
@SuppressWarnings("NullAway") // Dataflow analysis limitation
|
||||
private static @Nullable String initUrl(
|
||||
@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation,
|
||||
@Nullable StringValueResolver embeddedValueResolver) {
|
||||
|
||||
Reference in New Issue
Block a user