Fix overridden methods nullability

Issue: SPR-15869
This commit is contained in:
Sebastien Deleuze
2017-08-17 14:30:14 +02:00
parent 6b6c1d3e53
commit 73cf07e9a4
488 changed files with 1016 additions and 34 deletions

View File

@@ -42,6 +42,7 @@ public interface TargetSource extends TargetClassAware {
* @return the type of targets returned by this {@link TargetSource}
*/
@Override
@Nullable
Class<?> getTargetClass();
/**

View File

@@ -222,6 +222,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* @return the parameter names
*/
@Override
@Nullable
public String[] getParameterNames(Method method) {
this.argumentTypes = method.getParameterTypes();
this.numberOfRemainingUnboundArguments = this.argumentTypes.length;
@@ -310,6 +311,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* {@link #setRaiseExceptions(boolean) raiseExceptions} has been set to {@code true}
*/
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
if (this.raiseExceptions) {
throw new UnsupportedOperationException("An advice method can never be a constructor");

View File

@@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
import org.springframework.aop.framework.AopConfigException;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -76,6 +77,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory {
}
@Override
@Nullable
public ClassLoader getAspectClassLoader() {
return this.aspectClass.getClassLoader();
}

View File

@@ -19,6 +19,7 @@ package org.springframework.aop.aspectj;
import java.io.Serializable;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -53,6 +54,7 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory, Se
}
@Override
@Nullable
public ClassLoader getAspectClassLoader() {
return this.aspectInstance.getClass().getClassLoader();
}

View File

@@ -261,6 +261,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
private static class AspectJAnnotationParameterNameDiscoverer implements ParameterNameDiscoverer {
@Override
@Nullable
public String[] getParameterNames(Method method) {
if (method.getParameterCount() == 0) {
return new String[0];
@@ -283,6 +284,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
}
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
throw new UnsupportedOperationException("Spring AOP cannot handle constructor advice");
}

View File

@@ -91,6 +91,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
}
@Override
@Nullable
public ClassLoader getAspectClassLoader() {
return (this.beanFactory instanceof ConfigurableBeanFactory ?
((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader() :
@@ -103,6 +104,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
}
@Override
@Nullable
public Object getAspectCreationMutex() {
if (this.beanFactory.isSingleton(this.name)) {
// Rely on singleton semantics provided by the factory -> no local lock.

View File

@@ -74,6 +74,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
}
@Override
@Nullable
public ClassLoader getAspectClassLoader() {
return this.maaif.getAspectClassLoader();
}
@@ -84,6 +85,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
}
@Override
@Nullable
public Object getAspectCreationMutex() {
return this.maaif.getAspectCreationMutex();
}

View File

@@ -184,6 +184,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@Override
@Nullable
public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory,
int declarationOrderInAspect, String aspectName) {
@@ -218,6 +219,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
@Override
@Nullable
public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut,
MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) {

View File

@@ -110,6 +110,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
}
@Override
@Nullable
public Object getSource() {
return this.advisorDefinition.getSource();
}

View File

@@ -25,6 +25,7 @@ import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.lang.Nullable;
/**
* {@link BeanDefinitionParser} for the {@code aspectj-autoproxy} tag,
@@ -38,6 +39,7 @@ import org.springframework.beans.factory.xml.ParserContext;
class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element);
extendBeanDefinition(element, parserContext);

View File

@@ -97,6 +97,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
CompositeComponentDefinition compositeDef =
new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));

View File

@@ -84,6 +84,7 @@ public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFacto
@Override
@Nullable
public Method getObject() throws Exception {
return this.method;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.aop.config;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.AbstractComponentDefinition;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -62,6 +63,7 @@ public class PointcutComponentDefinition extends AbstractComponentDefinition {
}
@Override
@Nullable
public Object getSource() {
return this.pointcutDefinition.getSource();
}

View File

@@ -69,6 +69,7 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan
}
@Override
@Nullable
public ClassLoader getAspectClassLoader() {
if (this.beanFactory instanceof ConfigurableBeanFactory) {
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();

View File

@@ -221,6 +221,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
}
@Override
@Nullable
public Class<?> getObjectType() {
if (this.proxy != null) {
return this.proxy.getClass();

View File

@@ -247,6 +247,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* @return a fresh AOP proxy reflecting the current state of this factory
*/
@Override
@Nullable
public Object getObject() throws BeansException {
initializeAdvisorChain();
if (isSingleton()) {

View File

@@ -262,6 +262,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
}
@Override
@Nullable
public Object getUserAttribute(String key) {
return (this.userAttributes != null ? this.userAttributes.get(key) : null);
}

View File

@@ -218,6 +218,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
@Override
@Nullable
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
if (this.proxyTypes.isEmpty()) {
return null;
@@ -227,6 +228,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
}
@Override
@Nullable
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
return null;
}

View File

@@ -89,6 +89,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
//---------------------------------------------------------------------
@Override
@Nullable
public final TargetSource getTargetSource(Class<?> beanClass, String beanName) {
AbstractBeanFactoryBasedTargetSource targetSource =
createBeanFactoryBasedTargetSource(beanClass, beanName);

View File

@@ -20,6 +20,7 @@ import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
import org.springframework.aop.target.LazyInitTargetSource;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
/**
* TargetSourceCreator that enforces a LazyInitTargetSource for each bean
@@ -59,6 +60,7 @@ public class LazyInitTargetSourceCreator extends AbstractBeanFactoryBasedTargetS
}
@Override
@Nullable
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
Class<?> beanClass, String beanName) {

View File

@@ -20,6 +20,7 @@ import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource;
import org.springframework.aop.target.CommonsPool2TargetSource;
import org.springframework.aop.target.PrototypeTargetSource;
import org.springframework.aop.target.ThreadLocalTargetSource;
import org.springframework.lang.Nullable;
/**
* Convenient TargetSourceCreator using bean name prefixes to create one of three
@@ -41,6 +42,7 @@ public class QuickTargetSourceCreator extends AbstractBeanFactoryBasedTargetSour
public static final String PREFIX_PROTOTYPE = "!";
@Override
@Nullable
protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
Class<?> beanClass, String beanName) {

View File

@@ -138,6 +138,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
* @see #determineAsyncExecutor(Method)
*/
@Override
@Nullable
protected String getExecutorQualifier(Method method) {
return null;
}
@@ -151,6 +152,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
*/
@Override
@Nullable
protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
Executor defaultExecutor = super.getDefaultExecutor(beanFactory);
return (defaultExecutor != null ? defaultExecutor : new SimpleAsyncTaskExecutor());

View File

@@ -20,6 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.lang.Nullable;
/**
* {@link org.springframework.aop.TargetSource} implementation that will
@@ -65,6 +66,7 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource {
* @see #isInitialized()
*/
@Override
@Nullable
public synchronized Class<?> getTargetClass() {
return (this.lazyTarget != null ? this.lazyTarget.getClass() : null);
}

View File

@@ -22,6 +22,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.lang.Nullable;
/**
* Abstract base class for pooling {@link org.springframework.aop.TargetSource}
@@ -100,6 +101,7 @@ public abstract class AbstractPoolingTargetSource extends AbstractPrototypeBased
* APIs, so we're forgiving with our exception signature
*/
@Override
@Nullable
public abstract Object getTarget() throws Exception;
/**

View File

@@ -23,6 +23,8 @@ import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.lang.Nullable;
/**
* {@link org.springframework.aop.TargetSource} implementation that holds
* objects in a configurable Apache Commons2 Pool.
@@ -78,6 +80,7 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem
/**
* The Apache Commons {@code ObjectPool} used to pool target objects
*/
@Nullable
private ObjectPool pool;

View File

@@ -92,6 +92,7 @@ public class EmptyTargetSource implements TargetSource, Serializable {
* Always returns the specified target Class, or {@code null} if none.
*/
@Override
@Nullable
public Class<?> getTargetClass() {
return this.targetClass;
}
@@ -108,6 +109,7 @@ public class EmptyTargetSource implements TargetSource, Serializable {
* Always returns {@code null}.
*/
@Override
@Nullable
public Object getTarget() {
return null;
}

View File

@@ -17,6 +17,7 @@
package org.springframework.aop.target;
import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
/**
* {@link org.springframework.aop.TargetSource} that lazily accesses a
@@ -59,10 +60,12 @@ import org.springframework.beans.BeansException;
@SuppressWarnings("serial")
public class LazyInitTargetSource extends AbstractBeanFactoryBasedTargetSource {
@Nullable
private Object target;
@Override
@Nullable
public synchronized Object getTarget() throws BeansException {
if (this.target == null) {
this.target = getBeanFactory().getBean(getTargetBeanName());

View File

@@ -20,6 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.lang.Nullable;
/**
* Abstract {@link org.springframework.aop.TargetSource} implementation that
@@ -41,6 +42,7 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
protected Object targetObject;
private long refreshCheckDelay = -1;
@@ -80,6 +82,7 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
}
@Override
@Nullable
public final synchronized Object getTarget() {
if ((refreshCheckDelayElapsed() && requiresRefresh()) || this.targetObject == null) {
refresh();

View File

@@ -1,15 +0,0 @@
<html>
<body>
This package contains implementations of the org.springframework.aop.TargetSource interface.
<br>
The simplest implementation is the SingletonTargetSource, used by default in the AOP framework
to wrap a single target instance. This is normally appropriate.
<br>
Other provided implementations include pooling implementations, that provide a target
from a pool for each request, ensuring a single threaded programming model; and a
"prototype" implementation, that uses a new target instance for each invocation.
</body>
</html>