Add more @Nullable parameters based on null usage

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 21:35:52 +02:00
parent f9b319d3ba
commit 1f28825f9d
219 changed files with 441 additions and 355 deletions

View File

@@ -49,7 +49,7 @@ public class ContentDisposition {
/**
* Private constructor. See static factory methods in this class.
*/
private ContentDisposition(String type, String name, String filename, Charset charset, Long size) {
private ContentDisposition(@Nullable String type, @Nullable String name, @Nullable String filename, @Nullable Charset charset, @Nullable Long size) {
this.type = type;
this.name = name;
this.filename = filename;

View File

@@ -1333,7 +1333,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
* @see #set(String, String)
*/
@Override
public void add(String headerName, String headerValue) {
public void add(String headerName, @Nullable String headerValue) {
List<String> headerValues = this.headers.computeIfAbsent(headerName, k -> new LinkedList<>());
headerValues.add(headerValue);
}

View File

@@ -26,6 +26,7 @@ import java.util.List;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceRegion;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -213,7 +214,7 @@ public abstract class HttpRange {
private final Long lastPos;
public ByteRange(long firstPos, Long lastPos) {
public ByteRange(long firstPos, @Nullable Long lastPos) {
assertPositions(firstPos, lastPos);
this.firstPos = firstPos;
this.lastPos = lastPos;

View File

@@ -86,7 +86,7 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
return this.encoder.canEncode(elementType, mediaType);
}
@@ -139,7 +139,7 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
// Server side only...
@Override
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actualType,
public Mono<Void> write(Publisher<? extends T> inputStream, @Nullable ResolvableType actualType,
ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints) {

View File

@@ -76,7 +76,7 @@ public class FormHttpMessageWriter implements HttpMessageWriter<MultiValueMap<St
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
return MULTIVALUE_TYPE.isAssignableFrom(elementType) &&
(mediaType == null || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType));
}

View File

@@ -54,7 +54,7 @@ public interface HttpMessageWriter<T> {
* @param mediaType the media type for the write, possibly {@code null}
* @return {@code true} if writable, {@code false} otherwise
*/
boolean canWrite(ResolvableType elementType, MediaType mediaType);
boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType);
/**
* Write an given stream of object to the output message.
@@ -85,7 +85,7 @@ public interface HttpMessageWriter<T> {
* @param response the current response
* @return a {@link Mono} that indicates completion of writing or error
*/
default Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType actualType,
default Mono<Void> write(Publisher<? extends T> inputStream, @Nullable ResolvableType actualType,
ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request,
ServerHttpResponse response, Map<String, Object> hints) {

View File

@@ -93,7 +93,7 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter<Resource> {
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
return this.encoder.canEncode(elementType, mediaType);
}
@@ -152,7 +152,7 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter<Resource> {
return OptionalLong.empty();
}
private static Optional<Mono<Void>> zeroCopy(Resource resource, ResourceRegion region,
private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
ReactiveHttpOutputMessage message) {
if (message instanceof ZeroCopyHttpOutputMessage) {

View File

@@ -87,7 +87,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
return (mediaType == null || MediaType.TEXT_EVENT_STREAM.includes(mediaType) ||
ServerSentEvent.class.isAssignableFrom(elementType.resolve(Object.class)));
}
@@ -170,7 +170,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
}
@Override
public Mono<Void> write(Publisher<?> input, ResolvableType actualType, ResolvableType elementType,
public Mono<Void> write(Publisher<?> input, @Nullable ResolvableType actualType, ResolvableType elementType,
@Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response,
Map<String, Object> hints) {

View File

@@ -33,6 +33,7 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
import org.springframework.util.ObjectUtils;
@@ -80,7 +81,7 @@ public abstract class Jackson2CodecSupport {
return (mimeType == null || this.mimeTypes.stream().anyMatch(m -> m.isCompatibleWith(mimeType)));
}
protected JavaType getJavaType(Type type, Class<?> contextClass) {
protected JavaType getJavaType(Type type, @Nullable Class<?> contextClass) {
TypeFactory typeFactory = this.objectMapper.getTypeFactory();
return typeFactory.constructType(GenericTypeResolver.resolveType(type, contextClass));
}

View File

@@ -83,7 +83,7 @@ public class Jackson2JsonDecoder extends Jackson2CodecSupport implements HttpMes
}
@Override
public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementType,
public Flux<Object> decode(Publisher<DataBuffer> input, @Nullable ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return decodeInternal(this.fluxDecoder, input, elementType, mimeType, hints);

View File

@@ -97,7 +97,7 @@ class JsonObjectDecoder extends AbstractDecoder<DataBuffer> {
}
@Override
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream)

View File

@@ -110,7 +110,7 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
}
@Override
public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
return MultiValueMap.class.isAssignableFrom(elementType.getRawClass()) &&
(mediaType == null || MediaType.MULTIPART_FORM_DATA.isCompatibleWith(mediaType));
}

View File

@@ -91,7 +91,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
}
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
public Flux<Object> decode(Publisher<DataBuffer> inputStream, @Nullable ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Class<?> outputClass = elementType.getRawClass();

View File

@@ -71,7 +71,7 @@ public abstract class AbstractGenericHttpMessageConverter<T> extends AbstractHtt
}
@Override
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) {
return canWrite(clazz, mediaType);
}

View File

@@ -191,7 +191,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
* Future implementations might add some default behavior, however.
*/
@Override
public final T read(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
public final T read(@Nullable Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException {
return readInternal(clazz, inputMessage);
}

View File

@@ -159,7 +159,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter<B
}
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
public BufferedImage read(@Nullable Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
ImageInputStream imageInputStream = null;

View File

@@ -236,7 +236,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
}
@Override
public MultiValueMap<String, String> read(Class<? extends MultiValueMap<String, ?>> clazz,
public MultiValueMap<String, String> read(@Nullable Class<? extends MultiValueMap<String, ?>> clazz,
HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();

View File

@@ -79,7 +79,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
* @return {@code true} if writable; {@code false} otherwise
* @since 4.2
*/
boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType);
boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType);
/**
* Write an given object to the given output message.

View File

@@ -66,7 +66,7 @@ public interface HttpMessageConverter<T> {
* @throws IOException in case of I/O errors
* @throws HttpMessageNotReadableException in case of conversion errors
*/
T read(Class<? extends T> clazz, HttpInputMessage inputMessage)
T read(@Nullable Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException;
/**

View File

@@ -97,7 +97,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
}
@Override
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) {
if (!(type instanceof ParameterizedType)) {
return ResourceRegion.class.isAssignableFrom((Class<?>) type);
}

View File

@@ -317,7 +317,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
private final JsonFormat.Printer printer;
public ProtobufJavaUtilSupport(JsonFormat.Parser parser, JsonFormat.Printer printer) {
public ProtobufJavaUtilSupport(@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) {
this.parser = (parser != null ? parser : JsonFormat.parser());
this.printer = (printer != null ? printer : JsonFormat.printer());
}

View File

@@ -121,7 +121,7 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
* does not convert collections to XML.
*/
@Override
public boolean canWrite(@Nullable Type type, Class<?> clazz, @Nullable MediaType mediaType) {
public boolean canWrite(@Nullable Type type, @Nullable Class<?> clazz, @Nullable MediaType mediaType) {
return false;
}

View File

@@ -67,7 +67,7 @@ public abstract class AbstractMappingContentNegotiationStrategy extends MappingM
* an already extracted key.
* @since 3.2.16
*/
public List<MediaType> resolveMediaTypeKey(NativeWebRequest webRequest, String key)
public List<MediaType> resolveMediaTypeKey(@Nullable NativeWebRequest webRequest, String key)
throws HttpMediaTypeNotAcceptableException {
if (StringUtils.hasText(key)) {

View File

@@ -96,7 +96,7 @@ public class EscapedErrors implements Errors {
}
@Override
public void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
this.source.reject(errorCode, errorArgs, defaultMessage);
}

View File

@@ -50,7 +50,7 @@ public class DefaultDataBinderFactory implements WebDataBinderFactory {
@Override
@SuppressWarnings("deprecation")
public final WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target,
String objectName) throws Exception {
@Nullable String objectName) throws Exception {
WebDataBinder dataBinder = createBinderInstance(target, objectName, webRequest);
if (this.initializer != null) {

View File

@@ -36,6 +36,6 @@ public interface WebDataBinderFactory {
* @return the created {@link WebDataBinder} instance, never null
* @throws Exception raised if the creation and initialization of the data binder fails
*/
WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) throws Exception;
WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, @Nullable String objectName) throws Exception;
}

View File

@@ -98,7 +98,7 @@ public class WebExchangeBindException extends ServerWebInputException implements
}
@Override
public void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
this.bindingResult.reject(errorCode, errorArgs, defaultMessage);
}

View File

@@ -593,8 +593,8 @@ public interface RestOperations {
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
@Nullable
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException;
<T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
@Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException;
/**
* Execute the HTTP method to the given URI template, preparing the request with the
@@ -608,8 +608,8 @@ public interface RestOperations {
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
@Nullable
<T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException;
<T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
@Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException;
/**
* Execute the HTTP method to the given URL, preparing the request with the
@@ -621,7 +621,7 @@ public interface RestOperations {
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
@Nullable
<T> T execute(URI url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor) throws RestClientException;
<T> T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback,
@Nullable ResponseExtractor<T> responseExtractor) throws RestClientException;
}

View File

@@ -23,6 +23,7 @@ import java.util.Map;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -151,12 +152,12 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb
}
@Override
public boolean checkNotModified(String eTag) {
public boolean checkNotModified(@Nullable String eTag) {
return false;
}
@Override
public boolean checkNotModified(String etag, long lastModifiedTimestamp) {
public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestamp) {
return false;
}

View File

@@ -35,6 +35,7 @@ import javax.servlet.http.HttpSession;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -207,7 +208,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
}
@Override
public boolean checkNotModified(String etag, long lastModifiedTimestamp) {
public boolean checkNotModified(@Nullable String etag, long lastModifiedTimestamp) {
HttpServletResponse response = getResponse();
if (this.notModified || HttpStatus.OK.value() != response.getStatus()) {
return this.notModified;

View File

@@ -234,7 +234,7 @@ public interface WebRequest extends RequestAttributes {
* @return true if the request does not require further processing.
* @since 4.2
*/
boolean checkNotModified(String etag, long lastModifiedTimestamp);
boolean checkNotModified(@Nullable String etag, long lastModifiedTimestamp);
/**
* Get a short description of this request,

View File

@@ -180,7 +180,7 @@ public abstract class WebApplicationContextUtils {
* @param beanFactory the BeanFactory to configure
* @param sc the ServletContext that we're running within
*/
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, ServletContext sc) {
public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, @Nullable ServletContext sc) {
beanFactory.registerScope(WebApplicationContext.SCOPE_REQUEST, new RequestScope());
beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope());
if (sc != null) {
@@ -217,7 +217,7 @@ public abstract class WebApplicationContextUtils {
* @param servletConfig the ServletConfig of the containing Portlet
*/
public static void registerEnvironmentBeans(
ConfigurableListableBeanFactory bf, ServletContext servletContext, ServletConfig servletConfig) {
ConfigurableListableBeanFactory bf, ServletContext servletContext, @Nullable ServletConfig servletConfig) {
if (servletContext != null && !bf.containsBean(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME)) {
bf.registerSingleton(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME, servletContext);

View File

@@ -123,7 +123,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
* @exception Exception raised if no suitable argument resolver can be found,
* or if the method raised an exception
*/
public Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewContainer mavContainer,
Object... providedArgs) throws Exception {
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);

View File

@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;
/**
@@ -137,7 +138,7 @@ public interface ServerWebExchange {
* determined for the underlying resource
* @return true if the request does not require further processing.
*/
boolean checkNotModified(String etag, Instant lastModified);
boolean checkNotModified(@Nullable String etag, Instant lastModified);
/**

View File

@@ -25,6 +25,7 @@ import reactor.core.publisher.Mono;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
@@ -115,7 +116,7 @@ public class ServerWebExchangeDecorator implements ServerWebExchange {
}
@Override
public boolean checkNotModified(String etag, Instant lastModified) {
public boolean checkNotModified(@Nullable String etag, Instant lastModified) {
return getDelegate().checkNotModified(etag, lastModified);
}

View File

@@ -39,6 +39,7 @@ import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -215,7 +216,7 @@ public class DefaultServerWebExchange implements ServerWebExchange {
}
@Override
public boolean checkNotModified(String etag, Instant lastModified) {
public boolean checkNotModified(@Nullable String etag, Instant lastModified) {
HttpStatus status = getResponse().getStatusCode();
if (this.notModified || (status != null && !HttpStatus.OK.equals(status))) {
return this.notModified;

View File

@@ -155,7 +155,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
* @param path the path to initialize with
* @return the new {@code UriComponentsBuilder}
*/
public static UriComponentsBuilder fromPath(String path) {
public static UriComponentsBuilder fromPath(@Nullable String path) {
UriComponentsBuilder builder = new UriComponentsBuilder();
builder.path(path);
return builder;

View File

@@ -517,7 +517,7 @@ public class PathPattern implements Comparable<PathPattern> {
private final Map<String, String> matchingVariables;
PathRemainingMatchInfo(String pathRemaining) {
PathRemainingMatchInfo(@Nullable String pathRemaining) {
this(pathRemaining, Collections.emptyMap());
}