Add missing @Nullable annotations on parameters

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 12:37:54 +02:00
parent ad2c0f8410
commit b47d713e14
380 changed files with 1085 additions and 732 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.context.WebApplicationContext;
@@ -308,7 +309,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
@Override
public void postHandle(
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView)
throws ServletException {
if (request.getAttribute("test2x") != null) {
@@ -356,7 +357,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
@Override
public void postHandle(
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView)
throws ServletException {
if (request.getParameter("noView") != null) {
@@ -395,12 +396,12 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
}
@Override
public void postHandle(WebRequest request, ModelMap model) throws Exception {
public void postHandle(WebRequest request, @Nullable ModelMap model) throws Exception {
request.setAttribute("test3x", "test3x", WebRequest.SCOPE_REQUEST);
}
@Override
public void afterCompletion(WebRequest request, Exception ex) throws Exception {
public void afterCompletion(WebRequest request, @Nullable Exception ex) throws Exception {
request.setAttribute("test3y", "test3y", WebRequest.SCOPE_REQUEST);
}
}

View File

@@ -29,6 +29,7 @@ import org.springframework.core.io.Resource;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
@@ -254,7 +255,7 @@ class TestMessageCodesResolver implements MessageCodesResolver {
@Override
@SuppressWarnings("rawtypes")
public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType) {
public String[] resolveMessageCodes(String errorCode, String objectName, String field, @Nullable Class fieldType) {
return new String[] { "test.foo.bar" };
}

View File

@@ -64,6 +64,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockRequestDispatcher;
@@ -981,7 +982,7 @@ public class MvcNamespaceTests {
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, Errors errors) {
this.validatorInvoked = true;
}
}

View File

@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.ui.ModelMap;
@@ -190,11 +191,11 @@ public class InterceptorRegistryTests {
}
@Override
public void postHandle(WebRequest request, ModelMap model) throws Exception {
public void postHandle(WebRequest request, @Nullable ModelMap model) throws Exception {
}
@Override
public void afterCompletion(WebRequest request, Exception ex) throws Exception {
public void afterCompletion(WebRequest request, @Nullable Exception ex) throws Exception {
}
}

View File

@@ -36,6 +36,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockServletContext;
import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor;
@@ -354,7 +355,7 @@ public class WebMvcConfigurationSupportExtensionTests {
public Validator getValidator() {
return new Validator() {
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, Errors errors) {
errors.reject("invalid");
}
@Override

View File

@@ -26,6 +26,7 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletConfig;
@@ -81,7 +82,7 @@ public class CglibProxyControllerTests {
private void initServlet(final Class<?> controllerClass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();

View File

@@ -26,6 +26,7 @@ import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreato
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletConfig;
@@ -81,7 +82,7 @@ public class JdkProxyControllerTests {
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();

View File

@@ -22,6 +22,7 @@ import org.junit.After;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockServletConfig;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
@@ -76,7 +77,7 @@ public abstract class AbstractServletHandlerMethodTests {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
for (Class<?> clazz : controllerClasses) {
wac.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
}

View File

@@ -32,6 +32,7 @@ import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
@@ -121,7 +122,7 @@ public class HandlerMethodAnnotationDetectionTests {
class TestPointcut extends StaticMethodMatcherPointcut {
@Override
public boolean matches(Method method, Class<?> clazz) {
public boolean matches(Method method, @Nullable Class<?> clazz) {
return method.getName().equals("hashCode");
}
}
@@ -527,7 +528,7 @@ public class HandlerMethodAnnotationDetectionTests {
private static StaticMethodMatcherPointcut getControllerPointcut() {
return new StaticMethodMatcherPointcut() {
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return ((AnnotationUtils.findAnnotation(targetClass, Controller.class) != null) ||
(AnnotationUtils.findAnnotation(targetClass, RequestMapping.class) != null));
}

View File

@@ -34,6 +34,7 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
@@ -261,7 +262,7 @@ public class HttpEntityMethodProcessorTests {
private final class ValidatingBinderFactory implements WebDataBinderFactory {
@Override
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) {
public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
WebDataBinder dataBinder = new WebDataBinder(target, objectName);

View File

@@ -47,6 +47,7 @@ import org.springframework.http.CacheControl;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockMultipartFile;
@@ -443,7 +444,7 @@ public class RequestMappingHandlerAdapterIntegrationTests {
}
@Override
public void validate(Object target, Errors errors) {
public void validate(@Nullable Object target, Errors errors) {
errors.reject("error");
}
}

View File

@@ -35,6 +35,7 @@ import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockMultipartFile;
@@ -557,7 +558,7 @@ public class RequestPartMethodArgumentResolverTests {
private final class ValidatingBinderFactory implements WebDataBinderFactory {
@Override
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) throws Exception {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
WebDataBinder dataBinder = new WebDataBinder(target, objectName);

View File

@@ -36,6 +36,7 @@ import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
@@ -403,7 +404,7 @@ public class RequestResponseBodyMethodProcessorMockTests {
private final class ValidatingBinderFactory implements WebDataBinderFactory {
@Override
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
public WebDataBinder createBinder(NativeWebRequest webRequest, @Nullable Object target, String objectName) throws Exception {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
WebDataBinder dataBinder = new WebDataBinder(target, objectName);

View File

@@ -50,6 +50,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.util.MultiValueMap;
@@ -806,7 +807,7 @@ public class RequestResponseBodyMethodProcessorTests {
private final class ValidatingBinderFactory implements WebDataBinderFactory {
@Override
public WebDataBinder createBinder(NativeWebRequest request, Object target, String objectName) {
public WebDataBinder createBinder(NativeWebRequest request, @Nullable Object target, String objectName) {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();
WebDataBinder dataBinder = new WebDataBinder(target, objectName);
@@ -1013,7 +1014,7 @@ public class RequestResponseBodyMethodProcessorTests {
}
@Override
public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
public Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
return "default value for empty body";

View File

@@ -84,6 +84,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
import org.springframework.lang.Nullable;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockMultipartFile;
@@ -2489,7 +2490,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Override
@SuppressWarnings({"unchecked", "deprecation", "rawtypes"})
public void render(Map model, HttpServletRequest request, HttpServletResponse response)
public void render(@Nullable Map model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
TestBean tb = (TestBean) model.get("testBean");
if (tb == null) {
@@ -2534,7 +2535,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
return null;
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
public void render(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("viewName", viewName);
request.getSession().setAttribute("model", model);
}
@@ -2756,12 +2757,12 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
public static class NotReadableMessageConverter implements HttpMessageConverter<Object> {
@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
return true;
}
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
return true;
}
@@ -2777,7 +2778,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
}
@Override
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
public void write(Object o, @Nullable MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
throw new UnsupportedOperationException("Not implemented");
}
@@ -2792,12 +2793,12 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
}
@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
return supportedMediaTypes.contains(mediaType);
}
@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
return supportedMediaTypes.contains(mediaType);
}
@@ -2813,7 +2814,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
}
@Override
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
public void write(Object o, @Nullable MediaType contentType, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
outputMessage.getHeaders().setContentType(contentType);
outputMessage.getBody(); // force a header write
@@ -2924,7 +2925,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
return "text/html";
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
public void render(@Nullable Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.getWriter().write("myValue");
}