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

@@ -19,6 +19,8 @@ package org.springframework.aop;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.springframework.lang.Nullable;
/**
* Canonical MethodMatcher instance that matches all methods.
*
@@ -43,12 +45,12 @@ class TrueMethodMatcher implements MethodMatcher, Serializable {
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return true;
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
// Should never be invoked as isRuntime returns false.
throw new UnsupportedOperationException();
}

View File

@@ -698,7 +698,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return !this.adviceMethod.equals(method);
}

View File

@@ -61,7 +61,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
}
@Override
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
public void afterReturning(@Nullable Object returnValue, Method method, Object[] args, @Nullable Object target) throws Throwable {
if (shouldInvokeOnReturnValueOf(method, returnValue)) {
invokeAdviceMethod(getJoinPointMatch(), returnValue, null);
}

View File

@@ -277,7 +277,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
@Override
public boolean matches(Method method, Class<?> targetClass, boolean beanHasIntroductions) {
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean beanHasIntroductions) {
checkReadyToMatch();
Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
ShadowMatch shadowMatch = getShadowMatch(targetMethod, method);
@@ -306,7 +306,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return matches(method, targetClass, false);
}
@@ -317,7 +317,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
checkReadyToMatch();
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
ShadowMatch originalShadowMatch = getShadowMatch(method, method);

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.lang.Nullable;
/**
* Spring AOP advice that wraps an AspectJ before method.
@@ -39,7 +40,7 @@ public class AspectJMethodBeforeAdvice extends AbstractAspectJAdvice implements
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
invokeAdviceMethod(getJoinPointMatch(), null, null);
}

View File

@@ -31,6 +31,7 @@ import org.springframework.aop.aspectj.InstantiationModelAwarePointcutAdvisor;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.AspectJAnnotation;
import org.springframework.aop.support.DynamicMethodMatcherPointcut;
import org.springframework.aop.support.Pointcuts;
import org.springframework.lang.Nullable;
/**
* Internal implementation of AspectJPointcutAdvisor.
@@ -274,14 +275,14 @@ class InstantiationModelAwarePointcutAdvisorImpl
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
// We're either instantiated and matching on declared pointcut, or uninstantiated matching on either pointcut
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass)) ||
this.preInstantiationPointcut.getMethodMatcher().matches(method, targetClass);
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
// This can match only on declared pointcut.
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass));
}

View File

@@ -315,7 +315,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
super(aif.getAspectMetadata().getPerClausePointcut(), new MethodBeforeAdvice() {
@Override
public void before(Method method, Object[] args, Object target) {
public void before(Method method, Object[] args, @Nullable Object target) {
// Simply instantiate the aspect
aif.getAspectInstance();
}

View File

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -123,7 +124,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
if (this.proxyClassLoader == null) {
this.proxyClassLoader = classLoader;
}

View File

@@ -153,7 +153,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
@Override
public Object getProxy(ClassLoader classLoader) {
public Object getProxy(@Nullable ClassLoader classLoader) {
if (logger.isDebugEnabled()) {
logger.debug("Creating CGLIB proxy: target source is " + this.advised.getTargetSource());
}

View File

@@ -32,6 +32,7 @@ import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
import org.springframework.aop.support.MethodMatchers;
import org.springframework.lang.Nullable;
/**
* A simple but definitive way of working out an advice chain for a Method,
@@ -48,7 +49,7 @@ public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializ
@Override
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
Advised config, Method method, Class<?> targetClass) {
Advised config, Method method, @Nullable Class<?> targetClass) {
// This is somewhat tricky... We have to process introductions first,
// but we need to preserve order in the ultimate list.

View File

@@ -31,6 +31,7 @@ import org.springframework.aop.RawTargetAccess;
import org.springframework.aop.TargetSource;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.DecoratingProxy;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -113,7 +114,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
}
@Override
public Object getProxy(ClassLoader classLoader) {
public Object getProxy(@Nullable ClassLoader classLoader) {
if (logger.isDebugEnabled()) {
logger.debug("Creating JDK dynamic proxy: target source is " + this.advised.getTargetSource());
}

View File

@@ -45,6 +45,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -213,13 +214,13 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* containing BeanFactory for loading all bean classes. This can be
* overridden here for specific proxies.
*/
public void setProxyClassLoader(ClassLoader classLoader) {
public void setProxyClassLoader(@Nullable ClassLoader classLoader) {
this.proxyClassLoader = classLoader;
this.classLoaderConfigured = (classLoader != null);
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
if (!this.classLoaderConfigured) {
this.proxyClassLoader = classLoader;
}

View File

@@ -21,6 +21,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -81,7 +82,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
if (!this.classLoaderConfigured) {
this.proxyClassLoader = classLoader;
}

View File

@@ -28,6 +28,7 @@ import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ProxyMethodInvocation;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.lang.Nullable;
/**
* Spring's implementation of the AOP Alliance
@@ -240,7 +241,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
@Override
public void setUserAttribute(String key, Object value) {
public void setUserAttribute(String key, @Nullable Object value) {
if (value != null) {
if (this.userAttributes == null) {
this.userAttributes = new HashMap<>();

View File

@@ -24,6 +24,7 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
/**
* Generic auto proxy creator that builds AOP proxies for specific beans
@@ -66,7 +67,8 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource targetSource) {
@Nullable
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, @Nullable TargetSource targetSource) {
List<Advisor> advisors = findEligibleAdvisors(beanClass, beanName);
if (advisors.isEmpty()) {
return DO_NOT_PROXY;

View File

@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.aop.TargetSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.PatternMatchUtils;
import org.springframework.util.StringUtils;
@@ -73,7 +74,8 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
* Identify as bean to proxy if the bean name is in the configured list of names.
*/
@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource targetSource) {
@Nullable
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, @Nullable TargetSource targetSource) {
if (this.beanNames != null) {
for (String mappedName : this.beanNames) {
if (FactoryBean.class.isAssignableFrom(beanClass)) {

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -129,7 +130,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
* plus the name of the method.
*/
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return ((targetClass != null && matchesPattern(ClassUtils.getQualifiedMethodName(method, targetClass))) ||
matchesPattern(ClassUtils.getQualifiedMethodName(method)));
}

View File

@@ -80,7 +80,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
* some candidate classes.
*/
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return true;
}
@@ -90,7 +90,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
this.evaluations++;
for (StackTraceElement element : new Throwable().getStackTrace()) {

View File

@@ -19,6 +19,7 @@ package org.springframework.aop.support;
import java.lang.reflect.Method;
import org.springframework.aop.MethodMatcher;
import org.springframework.lang.Nullable;
/**
* Convenient abstract superclass for dynamic method matchers,
@@ -36,7 +37,7 @@ public abstract class DynamicMethodMatcher implements MethodMatcher {
* always returns true.
*/
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return true;
}

View File

@@ -114,13 +114,13 @@ public abstract class MethodMatchers {
}
@Override
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean hasIntroductions) {
return (matchesClass1(targetClass) && MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions)) ||
(matchesClass2(targetClass) && MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions));
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return (matchesClass1(targetClass) && this.mm1.matches(method, targetClass)) ||
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
}
@@ -139,7 +139,7 @@ public abstract class MethodMatchers {
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
}
@@ -230,13 +230,13 @@ public abstract class MethodMatchers {
}
@Override
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean hasIntroductions) {
return MethodMatchers.matches(this.mm1, method, targetClass, hasIntroductions) &&
MethodMatchers.matches(this.mm2, method, targetClass, hasIntroductions);
}
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return this.mm1.matches(method, targetClass) && this.mm2.matches(method, targetClass);
}
@@ -246,7 +246,7 @@ public abstract class MethodMatchers {
}
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
// Because a dynamic intersection may be composed of a static and dynamic part,
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
// it will probably be an unsupported operation.

View File

@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
@@ -78,7 +79,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
for (String mappedName : this.mappedNames) {
if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) {
return true;

View File

@@ -21,6 +21,7 @@ import java.lang.reflect.Method;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -97,7 +98,7 @@ public abstract class Pointcuts {
public static SetterPointcut INSTANCE = new SetterPointcut();
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return (method.getName().startsWith("set") &&
method.getParameterCount() == 1 &&
method.getReturnType() == Void.TYPE);
@@ -118,7 +119,7 @@ public abstract class Pointcuts {
public static GetterPointcut INSTANCE = new GetterPointcut();
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
return (method.getName().startsWith("get") &&
method.getParameterCount() == 0);
}

View File

@@ -19,6 +19,7 @@ package org.springframework.aop.support;
import java.lang.reflect.Method;
import org.springframework.aop.MethodMatcher;
import org.springframework.lang.Nullable;
/**
* Convenient abstract superclass for static method matchers, which don't care
@@ -32,7 +33,7 @@ public abstract class StaticMethodMatcher implements MethodMatcher {
}
@Override
public final boolean matches(Method method, Class<?> targetClass, Object... args) {
public final boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
// should never be invoked because isRuntime() returns false
throw new UnsupportedOperationException("Illegal MethodMatcher usage");
}

View File

@@ -22,6 +22,7 @@ import java.lang.reflect.Method;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.StaticMethodMatcher;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -66,7 +67,7 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher {
@Override
public boolean matches(Method method, Class<?> targetClass) {
public boolean matches(Method method, @Nullable Class<?> targetClass) {
if (matchesMethod(method)) {
return true;
}