Perform NullAway build-time checks in more modules
This commit enables null-safety build-time checks in all remaining modules except spring-test. See gh-32475
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.InvalidMimeTypeException;
|
||||
|
||||
/**
|
||||
@@ -36,8 +37,8 @@ public class InvalidMediaTypeException extends IllegalArgumentException {
|
||||
* @param mediaType the offending media type
|
||||
* @param message a detail message indicating the invalid part
|
||||
*/
|
||||
public InvalidMediaTypeException(String mediaType, String message) {
|
||||
super("Invalid media type \"" + mediaType + "\": " + message);
|
||||
public InvalidMediaTypeException(String mediaType, @Nullable String message) {
|
||||
super(message != null ? "Invalid media type \"" + mediaType + "\": " + message : "Invalid media type \"" + mediaType);
|
||||
this.mediaType = mediaType;
|
||||
}
|
||||
|
||||
|
||||
@@ -205,8 +205,8 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
RequestEntity<?> otherEntity = (RequestEntity<?>) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.method, otherEntity.method) &&
|
||||
return (other instanceof RequestEntity<?> otherEntity &&
|
||||
ObjectUtils.nullSafeEquals(this.method, otherEntity.method) &&
|
||||
ObjectUtils.nullSafeEquals(this.url, otherEntity.url));
|
||||
}
|
||||
|
||||
@@ -736,8 +736,8 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
UriTemplateRequestEntity<?> otherEntity = (UriTemplateRequestEntity<?>) other;
|
||||
return (ObjectUtils.nullSafeEquals(this.uriTemplate, otherEntity.uriTemplate) &&
|
||||
return (other instanceof UriTemplateRequestEntity<?> otherEntity &&
|
||||
ObjectUtils.nullSafeEquals(this.uriTemplate, otherEntity.uriTemplate) &&
|
||||
ObjectUtils.nullSafeEquals(this.uriVarsArray, otherEntity.uriVarsArray) &&
|
||||
ObjectUtils.nullSafeEquals(this.uriVarsMap, otherEntity.uriVarsMap));
|
||||
}
|
||||
|
||||
@@ -162,8 +162,7 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||
if (!super.equals(other)) {
|
||||
return false;
|
||||
}
|
||||
ResponseEntity<?> otherEntity = (ResponseEntity<?>) other;
|
||||
return ObjectUtils.nullSafeEquals(this.status, otherEntity.status);
|
||||
return (other instanceof ResponseEntity<?> otherEntity && ObjectUtils.nullSafeEquals(this.status, otherEntity.status));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,6 +63,7 @@ abstract class AbstractStreamingClientHttpRequest extends AbstractClientHttpRequ
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected final ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
|
||||
if (this.body == null && this.bodyStream != null) {
|
||||
this.body = outputStream -> this.bodyStream.writeTo(outputStream);
|
||||
|
||||
@@ -90,6 +90,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
||||
try {
|
||||
HttpRequest request = buildRequest(headers, body);
|
||||
|
||||
@@ -69,6 +69,7 @@ class JettyClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body body) throws IOException {
|
||||
if (!headers.isEmpty()) {
|
||||
this.request.headers(httpFields -> {
|
||||
|
||||
@@ -138,6 +138,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("NullAway")
|
||||
private Object buildEvent(List<String> lines, ResolvableType valueType, boolean shouldWrap,
|
||||
Map<String, Object> hints) {
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.3
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
final class MultipartParser extends BaseSubscriber<DataBuffer> {
|
||||
|
||||
private static final byte CR = '\r';
|
||||
@@ -115,6 +116,7 @@ final class MultipartParser extends BaseSubscriber<DataBuffer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("NullAway")
|
||||
protected void hookOnNext(DataBuffer value) {
|
||||
this.requestOutstanding.set(false);
|
||||
this.state.get().onNext(value);
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.springframework.util.FastByteArrayOutputStream;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.3
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
final class PartGenerator extends BaseSubscriber<MultipartParser.Token> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PartGenerator.class);
|
||||
|
||||
@@ -167,6 +167,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
private void writeResourceRegionCollection(Collection<ResourceRegion> resourceRegions,
|
||||
HttpOutputMessage outputMessage) throws IOException {
|
||||
|
||||
|
||||
@@ -329,7 +329,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
}
|
||||
|
||||
// Do not log warning for serializer not found (note: different message wording on Jackson 2.9)
|
||||
boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage().startsWith("Cannot find"));
|
||||
boolean debugLevel = (cause instanceof JsonMappingException && cause.getMessage() != null &&
|
||||
cause.getMessage().startsWith("Cannot find"));
|
||||
|
||||
if (debugLevel ? logger.isDebugEnabled() : logger.isWarnEnabled()) {
|
||||
String msg = "Failed to evaluate Jackson " + (type instanceof JavaType ? "de" : "") +
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.util.Assert;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public abstract class AbstractListenerReadPublisher<T> implements Publisher<T> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.util.Assert;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled to the {@link Subscriber}
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public abstract class AbstractListenerWriteFlushProcessor<T> implements Processor<Publisher<? extends T>, Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.util.StringUtils;
|
||||
* @since 5.0
|
||||
* @param <T> the type of element signaled to the {@link Subscriber}
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
public abstract class AbstractListenerWriteProcessor<T> implements Processor<T, Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,7 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest {
|
||||
return new URI(url.toString());
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullAway")
|
||||
private static MultiValueMap<String, String> initHeaders(
|
||||
MultiValueMap<String, String> headerValues, HttpServletRequest request) {
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
*/
|
||||
@SuppressWarnings("NullAway")
|
||||
class WriteResultPublisher implements Publisher<Void> {
|
||||
|
||||
/**
|
||||
|
||||
@@ -489,7 +489,9 @@ final class HttpServiceMethod {
|
||||
|
||||
return request -> client.exchangeForEntityFlux(request, bodyType)
|
||||
.map(entity -> {
|
||||
Object body = reactiveAdapter.fromPublisher(entity.getBody());
|
||||
Flux<?> entityBody = entity.getBody();
|
||||
Assert.state(entityBody != null, "Entity body must not be null");
|
||||
Object body = reactiveAdapter.fromPublisher(entityBody);
|
||||
return new ResponseEntity<>(body, entity.getHeaders(), entity.getStatusCode());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user