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

@@ -26,6 +26,7 @@ import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.*;
@@ -237,7 +238,7 @@ class SimpleSpringBeforeAdvice implements MethodBeforeAdvice, BeanNameAware {
* @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object)
*/
@Override
public void before(Method method, Object[] args, Object target)
public void before(Method method, Object[] args, @Nullable Object target)
throws Throwable {
this.collaborator.beforeAdviceOne(this.name);
}

View File

@@ -26,6 +26,7 @@ import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.*;
@@ -129,7 +130,7 @@ public class BeanNamePointcutTests {
private int interceptionCount;
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
interceptionCount++;
}
}

View File

@@ -48,6 +48,7 @@ import org.springframework.core.NestedRuntimeException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.lang.Nullable;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.tests.sample.beans.INestedTestBean;
@@ -574,14 +575,14 @@ class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor {
public TestBeanAdvisor() {
setAdvice(new MethodBeforeAdvice() {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
++count;
}
});
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return ITestBean.class.isAssignableFrom(targetClass);
}

View File

@@ -57,6 +57,7 @@ import org.springframework.aop.support.Pointcuts;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.aop.target.HotSwappableTargetSource;
import org.springframework.aop.target.SingletonTargetSource;
import org.springframework.lang.Nullable;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.tests.TimeStamped;
@@ -1137,7 +1138,7 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial")
StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return "haveBirthday".equals(m.getName());
}
};
@@ -1216,7 +1217,7 @@ public abstract class AbstractAopProxyTests {
NopInterceptor overLoadVoids = new NopInterceptor();
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadVoids) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().equals("overload") && m.getParameterCount() == 0;
}
});
@@ -1224,7 +1225,7 @@ public abstract class AbstractAopProxyTests {
NopInterceptor overLoadInts = new NopInterceptor();
pc.addAdvisor(new StaticMethodMatcherPointcutAdvisor(overLoadInts) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().equals("overload") && m.getParameterCount() == 1 &&
m.getParameterTypes()[0].equals(int.class);
}
@@ -1313,7 +1314,7 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial")
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cba) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getParameterCount() == 0;
}
};
@@ -1394,7 +1395,7 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial")
Advisor matchesNoArgs = new StaticMethodMatcherPointcutAdvisor(cca) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getParameterCount() == 0 || "exceptional".equals(m.getName());
}
};
@@ -1477,7 +1478,7 @@ public abstract class AbstractAopProxyTests {
class SummingAfterAdvice implements AfterReturningAdvice {
public int sum;
@Override
public void afterReturning(Object returnValue, Method m, Object[] args, Object target) throws Throwable {
public void afterReturning(@Nullable Object returnValue, Method m, Object[] args, @Nullable Object target) throws Throwable {
sum += ((Integer) returnValue).intValue();
}
}
@@ -1485,7 +1486,7 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial")
Advisor matchesInt = new StaticMethodMatcherPointcutAdvisor(aa) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getReturnType() == int.class;
}
};
@@ -1543,7 +1544,7 @@ public abstract class AbstractAopProxyTests {
@SuppressWarnings("serial")
Advisor matchesEchoInvocations = new StaticMethodMatcherPointcutAdvisor(th) {
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().startsWith("echo");
}
};
@@ -1688,11 +1689,11 @@ public abstract class AbstractAopProxyTests {
super(cleaner);
setPointcut(new DynamicMethodMatcherPointcut() {
@Override
public boolean matches(Method m, Class<?> targetClass, Object... args) {
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
return args[0] == null;
}
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().startsWith("set") &&
m.getParameterCount() == 1 &&
m.getParameterTypes()[0].equals(String.class);
@@ -1711,7 +1712,7 @@ public abstract class AbstractAopProxyTests {
super(mi);
setPointcut(new DynamicMethodMatcherPointcut() {
@Override
public boolean matches(Method m, Class<?> targetClass, Object... args) {
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
boolean run = m.getName().contains(pattern);
if (run) ++count;
return run;
@@ -1730,13 +1731,13 @@ public abstract class AbstractAopProxyTests {
super(mi);
setPointcut(new DynamicMethodMatcherPointcut() {
@Override
public boolean matches(Method m, Class<?> targetClass, Object... args) {
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
boolean run = m.getName().contains(pattern);
if (run) ++count;
return run;
}
@Override
public boolean matches(Method m, Class<?> clazz) {
public boolean matches(Method m, @Nullable Class<?> clazz) {
return m.getName().startsWith("set");
}
});
@@ -1754,7 +1755,7 @@ public abstract class AbstractAopProxyTests {
this.pattern = pattern;
}
@Override
public boolean matches(Method m, Class<?> targetClass) {
public boolean matches(Method m, @Nullable Class<?> targetClass) {
return m.getName().contains(pattern);
}
}
@@ -1947,12 +1948,12 @@ public abstract class AbstractAopProxyTests {
AfterReturningAdvice, ThrowsAdvice {
@Override
public void before(Method m, Object[] args, Object target) throws Throwable {
public void before(Method m, Object[] args, @Nullable Object target) throws Throwable {
count(m);
}
@Override
public void afterReturning(Object o, Method m, Object[] args, Object target)
public void afterReturning(@Nullable Object o, Method m, Object[] args, @Nullable Object target)
throws Throwable {
count(m);
}

View File

@@ -49,6 +49,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationListener;
import org.springframework.context.TestListener;
import org.springframework.core.io.ClassPathResource;
import org.springframework.lang.Nullable;
import org.springframework.tests.TimeStamped;
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.aop.advice.MyThrowsHandler;
@@ -730,7 +731,7 @@ public class ProxyFactoryBeanTests {
});
setPointcut(new DynamicMethodMatcherPointcut() {
@Override
public boolean matches(Method m, Class<?> targetClass, Object... args) {
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
return m.getReturnType() == Void.TYPE;
}
});

View File

@@ -42,6 +42,7 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
@@ -395,7 +396,8 @@ public class AutoProxyCreatorTests {
}
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, TargetSource customTargetSource) {
@Nullable
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, @Nullable TargetSource customTargetSource) {
if (StaticMessageSource.class.equals(beanClass)) {
return DO_NOT_PROXY;
}

View File

@@ -22,6 +22,7 @@ import org.junit.Test;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -49,7 +50,7 @@ public class BeanNameAutoProxyCreatorInitTests {
class NullChecker implements MethodBeforeAdvice {
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
check(args);
}

View File

@@ -40,6 +40,7 @@ import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -331,7 +332,8 @@ public class CacheReproTests {
}
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
@Nullable
protected Collection<String> getCacheNames(@Nullable CacheOperationInvocationContext<?> context) {
String cacheName = (String) context.getArgs()[0];
if (cacheName != null) {
return Collections.singleton(cacheName);

View File

@@ -36,6 +36,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
@@ -261,7 +262,8 @@ public class CacheResolverCustomizationTests {
}
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
@Nullable
protected Collection<String> getCacheNames(@Nullable CacheOperationInvocationContext<?> context) {
String cacheName = (String) context.getArgs()[1];
return Collections.singleton(cacheName);
}
@@ -275,7 +277,8 @@ public class CacheResolverCustomizationTests {
}
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
@Nullable
protected Collection<String> getCacheNames(@Nullable CacheOperationInvocationContext<?> context) {
return null;
}
}

View File

@@ -58,6 +58,7 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.util.SerializationTestUtils;
@@ -291,7 +292,7 @@ public class ComponentScanAnnotationIntegrationTests {
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
this.classLoader = classLoader;
}

View File

@@ -34,6 +34,7 @@ import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@@ -80,7 +81,7 @@ public class ImportBeanDefinitionRegistrarTests {
static Environment environment;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
SampleRegistrar.classLoader = classLoader;
}

View File

@@ -41,6 +41,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@@ -112,7 +113,7 @@ public class ImportSelectorTests {
static Environment environment;
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
SampleRegistrar.classLoader = classLoader;
}

View File

@@ -31,6 +31,7 @@ import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ResourceTestBean;
import static org.hamcrest.Matchers.*;
@@ -78,7 +79,8 @@ public class ConversionServiceFactoryBeanTests {
return Collections.singleton(new ConvertiblePair(String.class, Baz.class));
}
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return new Baz();
}
});

View File

@@ -34,6 +34,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -97,7 +98,7 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
private static int counter = 0;
@Override
public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
public void multicastEvent(ApplicationEvent event, @Nullable ResolvableType eventType) {
super.multicastEvent(event, eventType);
counter++;
}

View File

@@ -30,6 +30,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
import org.springframework.validation.DataBinder;
@@ -51,7 +52,7 @@ public class NumberFormattingTests {
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
public String resolveStringValue(@Nullable String strVal) {
if ("${pattern}".equals(strVal)) {
return "#,##.00";
}

View File

@@ -20,6 +20,7 @@ import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.lang.Nullable;
public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
@@ -28,7 +29,7 @@ public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
private int countThrows = 0;
@Override
public void before(Method method, Object[] objects, Object o) throws Throwable {
public void before(Method method, Object[] objects, @Nullable Object o) throws Throwable {
countBefore++;
// System.out.println("Method:" + method.getName());
}

View File

@@ -57,6 +57,7 @@ import org.springframework.format.Formatter;
import org.springframework.format.number.NumberStyleFormatter;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.BeanWithObjectProperty;
import org.springframework.tests.sample.beans.DerivedTestBean;
import org.springframework.tests.sample.beans.ITestBean;
@@ -2167,7 +2168,7 @@ public class DataBinderTests {
}
@Override
public void validate(Object obj, Errors errors) {
public void validate(@Nullable Object obj, Errors errors) {
TestBean tb = (TestBean) obj;
if (tb.getAge() < 32) {
errors.rejectValue("age", "TOO_YOUNG", "simply too young");
@@ -2196,7 +2197,7 @@ public class DataBinderTests {
}
@Override
public void validate(Object obj, Errors errors) {
public void validate(@Nullable Object obj, Errors errors) {
TestBean tb = (TestBean) obj;
if (tb == null || "XXX".equals(tb.getName())) {
errors.rejectValue("", "SPOUSE_NOT_AVAILABLE");

View File

@@ -18,6 +18,7 @@ package org.springframework.validation;
import org.junit.Test;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
@@ -168,7 +169,7 @@ public class ValidationUtilsTests {
}
@Override
public void validate(Object obj, Errors errors) {
public void validate(@Nullable Object obj, Errors errors) {
ValidationUtils.rejectIfEmpty(errors, "name", "EMPTY", "You must enter a name!");
}
}
@@ -182,7 +183,7 @@ public class ValidationUtilsTests {
}
@Override
public void validate(Object obj, Errors errors) {
public void validate(@Nullable Object obj, Errors errors) {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "EMPTY_OR_WHITESPACE", "You must enter a name!");
}
}