Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
parent
ffc3f6d87d
commit
f813712f5b
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*<
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -31,14 +31,14 @@ import org.springframework.lang.Nullable;
|
|||
* {@code TargetSources} directly: this is an AOP framework interface.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public interface TargetSource extends TargetClassAware {
|
||||
|
||||
/**
|
||||
* Return the type of targets returned by this {@link TargetSource}.
|
||||
* <p>Can return {@code null}, although certain usages of a
|
||||
* {@code TargetSource} might just work with a predetermined
|
||||
* target class.
|
||||
* <p>Can return {@code null}, although certain usages of a {@code TargetSource}
|
||||
* might just work with a predetermined target class.
|
||||
* @return the type of targets returned by this {@link TargetSource}
|
||||
*/
|
||||
@Override
|
||||
|
@ -46,9 +46,8 @@ public interface TargetSource extends TargetClassAware {
|
|||
|
||||
/**
|
||||
* Will all calls to {@link #getTarget()} return the same object?
|
||||
* <p>In that case, there will be no need to invoke
|
||||
* {@link #releaseTarget(Object)}, and the AOP framework can cache
|
||||
* the return value of {@link #getTarget()}.
|
||||
* <p>In that case, there will be no need to invoke {@link #releaseTarget(Object)},
|
||||
* and the AOP framework can cache the return value of {@link #getTarget()}.
|
||||
* @return {@code true} if the target is immutable
|
||||
* @see #getTarget
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -208,6 +208,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
/**
|
||||
* Return the ClassLoader for aspect instances.
|
||||
*/
|
||||
@Nullable
|
||||
public final ClassLoader getAspectClassLoader() {
|
||||
return this.aspectInstanceFactory.getAspectClassLoader();
|
||||
}
|
||||
|
@ -296,8 +297,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException("Returning name '" + name +
|
||||
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
|
||||
"Root cause: " + ex);
|
||||
"' is neither a valid argument name nor the fully-qualified " +
|
||||
"name of a Java type on the classpath. Root cause: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -306,6 +307,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
return this.discoveredReturningType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Type getDiscoveredReturningGenericType() {
|
||||
return this.discoveredReturningGenericType;
|
||||
}
|
||||
|
@ -330,8 +332,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException("Throwing name '" + name +
|
||||
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
|
||||
"Root cause: " + ex);
|
||||
"' is neither a valid argument name nor the fully-qualified " +
|
||||
"name of a Java type on the classpath. Root cause: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -549,7 +551,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
* @param ex the exception thrown by the method execution (may be null)
|
||||
* @return the empty array if there are no arguments
|
||||
*/
|
||||
protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) {
|
||||
protected Object[] argBinding(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
|
||||
@Nullable Object returnValue, @Nullable Throwable ex) {
|
||||
|
||||
calculateArgumentBindings();
|
||||
|
||||
// AMC start
|
||||
|
@ -608,13 +612,16 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
* @return the invocation result
|
||||
* @throws Throwable in case of invocation failure
|
||||
*/
|
||||
protected Object invokeAdviceMethod(JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable {
|
||||
protected Object invokeAdviceMethod(
|
||||
@Nullable JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex)
|
||||
throws Throwable {
|
||||
|
||||
return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex));
|
||||
}
|
||||
|
||||
// As above, but in this case we are given the join point.
|
||||
protected Object invokeAdviceMethod(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t)
|
||||
throws Throwable {
|
||||
protected Object invokeAdviceMethod(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
|
||||
@Nullable Object returnValue, @Nullable Throwable t) throws Throwable {
|
||||
|
||||
return invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t));
|
||||
}
|
||||
|
@ -649,6 +656,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
/**
|
||||
* Get the current join point match at the join point we are being dispatched on.
|
||||
*/
|
||||
@Nullable
|
||||
protected JoinPointMatch getJoinPointMatch() {
|
||||
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
|
||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||
|
@ -663,8 +671,10 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
|||
// 'last man wins' which is not what we want at all.
|
||||
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
||||
// are guaranteed to bind in exactly the same way.
|
||||
@Nullable
|
||||
protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) {
|
||||
return (JoinPointMatch) pmi.getUserAttribute(this.pointcut.getExpression());
|
||||
String expression = this.pointcut.getExpression();
|
||||
return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Interface implemented to provide an instance of an AspectJ aspect.
|
||||
|
@ -40,8 +41,10 @@ public interface AspectInstanceFactory extends Ordered {
|
|||
|
||||
/**
|
||||
* Expose the aspect class loader that this factory uses.
|
||||
* @return the aspect class loader (never {@code null})
|
||||
* @return the aspect class loader (or {@code null} for the bootstrap loader)
|
||||
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
|
||||
*/
|
||||
@Nullable
|
||||
ClassLoader getAspectClassLoader();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -183,10 +183,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
* Create a new discoverer that attempts to discover parameter names
|
||||
* from the given pointcut expression.
|
||||
*/
|
||||
public AspectJAdviceParameterNameDiscoverer(String pointcutExpression) {
|
||||
public AspectJAdviceParameterNameDiscoverer(@Nullable String pointcutExpression) {
|
||||
this.pointcutExpression = pointcutExpression;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
|
||||
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
|
||||
|
@ -214,6 +215,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
this.throwingName = throwingName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deduce the parameter names for an advice method.
|
||||
* <p>See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
|
||||
|
@ -475,8 +477,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
* If the token starts meets Java identifier conventions, it's in.
|
||||
*/
|
||||
@Nullable
|
||||
private String maybeExtractVariableName(String candidateToken) {
|
||||
if (candidateToken == null || candidateToken.equals("")) {
|
||||
private String maybeExtractVariableName(@Nullable String candidateToken) {
|
||||
if (!StringUtils.hasLength(candidateToken)) {
|
||||
return null;
|
||||
}
|
||||
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
|
||||
|
@ -498,7 +500,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
* Given an args pointcut body (could be {@code args} or {@code at_args}),
|
||||
* add any candidate variable names to the given list.
|
||||
*/
|
||||
private void maybeExtractVariableNamesFromArgs(String argsSpec, List<String> varNames) {
|
||||
private void maybeExtractVariableNamesFromArgs(@Nullable String argsSpec, List<String> varNames) {
|
||||
if (argsSpec == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -781,7 +783,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
|
||||
private String text;
|
||||
|
||||
public PointcutBody(int tokens, String text) {
|
||||
public PointcutBody(int tokens, @Nullable String text) {
|
||||
this.numTokensConsumed = tokens;
|
||||
this.text = text;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -57,6 +57,7 @@ import org.springframework.beans.factory.FactoryBean;
|
|||
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -196,6 +197,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
/**
|
||||
* Determine the ClassLoader to use for pointcut evaluation.
|
||||
*/
|
||||
@Nullable
|
||||
private ClassLoader determinePointcutClassLoader() {
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
|
||||
|
@ -209,21 +211,27 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
/**
|
||||
* Build the underlying AspectJ pointcut expression.
|
||||
*/
|
||||
private PointcutExpression buildPointcutExpression(ClassLoader classLoader) {
|
||||
private PointcutExpression buildPointcutExpression(@Nullable ClassLoader classLoader) {
|
||||
PointcutParser parser = initializePointcutParser(classLoader);
|
||||
PointcutParameter[] pointcutParameters = new PointcutParameter[this.pointcutParameterNames.length];
|
||||
for (int i = 0; i < pointcutParameters.length; i++) {
|
||||
pointcutParameters[i] = parser.createPointcutParameter(
|
||||
this.pointcutParameterNames[i], this.pointcutParameterTypes[i]);
|
||||
}
|
||||
return parser.parsePointcutExpression(replaceBooleanOperators(getExpression()),
|
||||
return parser.parsePointcutExpression(replaceBooleanOperators(resolveExpression()),
|
||||
this.pointcutDeclarationScope, pointcutParameters);
|
||||
}
|
||||
|
||||
private String resolveExpression() {
|
||||
String expression = getExpression();
|
||||
Assert.state(expression != null, "No expression set");
|
||||
return expression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the underlying AspectJ pointcut parser.
|
||||
*/
|
||||
private PointcutParser initializePointcutParser(ClassLoader classLoader) {
|
||||
private PointcutParser initializePointcutParser(@Nullable ClassLoader classLoader) {
|
||||
PointcutParser parser = PointcutParser
|
||||
.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(
|
||||
SUPPORTED_PRIMITIVES, classLoader);
|
||||
|
@ -301,7 +309,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
// we say this is not a match as in Spring there will never be a different
|
||||
// runtime subtype.
|
||||
RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch);
|
||||
return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass));
|
||||
return (!walker.testsSubtypeSensitiveVars() ||
|
||||
(targetClass != null && walker.testTargetInstanceOfResidue(targetClass)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,7 +363,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
* type but not 'this' (as would be the case of JDK dynamic proxies).
|
||||
* <p>See SPR-2979 for the original bug.
|
||||
*/
|
||||
if (pmi != null) { // there is a current invocation
|
||||
if (pmi != null && thisObject != null) { // there is a current invocation
|
||||
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(originalShadowMatch);
|
||||
if (!originalMethodResidueTest.testThisInstanceOfResidue(thisObject.getClass())) {
|
||||
return false;
|
||||
|
@ -375,6 +384,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getCurrentProxiedBeanName() {
|
||||
return ProxyCreationContext.getCurrentProxiedBeanName();
|
||||
}
|
||||
|
@ -411,7 +421,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
// 'last man wins' which is not what we want at all.
|
||||
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
||||
// are guaranteed to bind in exactly the same way.
|
||||
invocation.setUserAttribute(getExpression(), jpm);
|
||||
invocation.setUserAttribute(resolveExpression(), jpm);
|
||||
}
|
||||
|
||||
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
|
||||
|
@ -600,7 +610,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||
return false;
|
||||
}
|
||||
|
||||
private FuzzyBoolean contextMatch(Class<?> targetType) {
|
||||
private FuzzyBoolean contextMatch(@Nullable Class<?> targetType) {
|
||||
String advisedBeanName = getCurrentProxiedBeanName();
|
||||
if (advisedBeanName == null) { // no proxy creation in progress
|
||||
// abstain; can't return YES, since that will make pointcut with negation fail
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,6 +20,7 @@ import org.springframework.aop.Pointcut;
|
|||
import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Spring AOP Advisor that can be used for any AspectJ pointcut expression.
|
||||
|
@ -37,6 +38,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
|
|||
this.pointcut.setExpression(expression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getExpression() {
|
||||
return this.pointcut.getExpression();
|
||||
}
|
||||
|
@ -45,6 +47,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
|
|||
this.pointcut.setLocation(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLocation() {
|
||||
return this.pointcut.getLocation();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -212,6 +212,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
|||
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String resolveExpression(A annotation) throws Exception {
|
||||
String expression = null;
|
||||
for (String methodName : EXPRESSION_PROPERTIES) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -119,7 +119,9 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
|||
*/
|
||||
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
|
||||
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
||||
advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
|
||||
Class<?> targetClass = getTargetClass();
|
||||
Assert.state(targetClass != null, "Unresolvable target class");
|
||||
advisors = AopUtils.findAdvisorsThatCanApply(advisors, targetClass);
|
||||
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
||||
AnnotationAwareOrderComparator.sort(advisors);
|
||||
addAdvisors(advisors);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactory;
|
|||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.OrderUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
@ -58,7 +59,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
|||
* @param name name of the bean
|
||||
*/
|
||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
|
||||
this(beanFactory, name, beanFactory.getType(name));
|
||||
this(beanFactory, name, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,13 +69,19 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
|||
* @param beanFactory BeanFactory to obtain instance(s) from
|
||||
* @param name the name of the bean
|
||||
* @param type the type that should be introspected by AspectJ
|
||||
* ({@code null} indicates resolution through {@link BeanFactory#getType} via the bean name)
|
||||
*/
|
||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class<?> type) {
|
||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, @Nullable Class<?> type) {
|
||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||
Assert.notNull(name, "Bean name must not be null");
|
||||
this.beanFactory = beanFactory;
|
||||
this.name = name;
|
||||
this.aspectMetadata = new AspectMetadata(type, name);
|
||||
Class<?> resolvedType = type;
|
||||
if (type == null) {
|
||||
resolvedType = beanFactory.getType(name);
|
||||
Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class");
|
||||
}
|
||||
this.aspectMetadata = new AspectMetadata(resolvedType, name);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -45,6 +45,9 @@ import org.springframework.lang.Nullable;
|
|||
class InstantiationModelAwarePointcutAdvisorImpl
|
||||
implements InstantiationModelAwarePointcutAdvisor, AspectJPrecedenceInformation, Serializable {
|
||||
|
||||
private static Advice EMPTY_ADVICE = new Advice() {};
|
||||
|
||||
|
||||
private final AspectJExpressionPointcut declaredPointcut;
|
||||
|
||||
private final Class<?> declaringClass;
|
||||
|
@ -157,9 +160,10 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
|||
}
|
||||
|
||||
|
||||
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) {
|
||||
return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut,
|
||||
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
|
||||
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
|
||||
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||
return (advice != null ? advice : EMPTY_ADVICE);
|
||||
}
|
||||
|
||||
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -132,7 +132,9 @@ class AspectJPrecedenceComparator implements Comparator<Advisor> {
|
|||
|
||||
// pre-condition is that hasAspectName returned true
|
||||
private String getAspectName(Advisor anAdvisor) {
|
||||
return AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor).getAspectName();
|
||||
AspectJPrecedenceInformation pi = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
|
||||
Assert.state(pi != null, "Unresolvable precedence information");
|
||||
return pi.getAspectName();
|
||||
}
|
||||
|
||||
private int getAspectDeclarationOrder(Advisor anAdvisor) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.ManagedList;
|
|||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
@ -105,8 +106,8 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
|
||||
List<String> list = (List<String>)
|
||||
beanDefinition.getPropertyValues().getPropertyValue("interceptorNames").getValue();
|
||||
List<String> list = (List<String>) beanDefinition.getPropertyValues().get("interceptorNames");
|
||||
Assert.state(list != null, "Missing 'interceptorNames' property");
|
||||
list.add(interceptorName);
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,9 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
|||
}
|
||||
|
||||
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
|
||||
return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
|
||||
String beanClassName = interceptorDefinition.getBeanClassName();
|
||||
return (StringUtils.hasLength(beanClassName) ?
|
||||
StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,6 +20,7 @@ import org.springframework.beans.MutablePropertyValues;
|
|||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanReference;
|
||||
import org.springframework.beans.factory.parsing.AbstractComponentDefinition;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +51,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
|||
}
|
||||
|
||||
public AdvisorComponentDefinition(
|
||||
String advisorBeanName, BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
|
||||
String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
|
||||
|
||||
Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
|
||||
Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
|
||||
|
@ -60,9 +61,10 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
|||
}
|
||||
|
||||
|
||||
private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
|
||||
private void unwrapDefinitions(BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
|
||||
MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
|
||||
BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue();
|
||||
BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
|
||||
Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");
|
||||
|
||||
if (pointcutDefinition != null) {
|
||||
this.beanReferences = new BeanReference[] {adviceReference};
|
||||
|
@ -70,7 +72,8 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
|||
this.description = buildDescription(adviceReference, pointcutDefinition);
|
||||
}
|
||||
else {
|
||||
BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue();
|
||||
BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
|
||||
Assert.state(pointcutReference != null, "Missing 'pointcut' property");
|
||||
this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
|
||||
this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
|
||||
this.description = buildDescription(adviceReference, pointcutReference);
|
||||
|
@ -78,16 +81,15 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
|||
}
|
||||
|
||||
private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) {
|
||||
return new StringBuilder("Advisor <advice(ref)='").
|
||||
append(adviceReference.getBeanName()).append("', pointcut(expression)=[").
|
||||
append(pointcutDefinition.getPropertyValues().getPropertyValue("expression").getValue()).
|
||||
append("]>").toString();
|
||||
return "Advisor <advice(ref)='" +
|
||||
adviceReference.getBeanName() + "', pointcut(expression)=[" +
|
||||
pointcutDefinition.getPropertyValues().get("expression") + "]>";
|
||||
}
|
||||
|
||||
private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) {
|
||||
return new StringBuilder("Advisor <advice(ref)='").
|
||||
append(adviceReference.getBeanName()).append("', pointcut(ref)='").
|
||||
append(pointcutReference.getBeanName()).append("'>").toString();
|
||||
return "Advisor <advice(ref)='" +
|
||||
adviceReference.getBeanName() + "', pointcut(ref)='" +
|
||||
pointcutReference.getBeanName() + "'>";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -67,27 +67,39 @@ public abstract class AopConfigUtils {
|
|||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||
return registerAutoProxyCreatorIfNecessary(registry, null);
|
||||
}
|
||||
|
||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
||||
@Nullable
|
||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||
return registerAspectJAutoProxyCreatorIfNecessary(registry, null);
|
||||
}
|
||||
|
||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||
return registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry, null);
|
||||
}
|
||||
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
||||
@Nullable
|
||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
|
||||
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
|
||||
}
|
||||
|
||||
|
@ -106,8 +118,11 @@ public abstract class AopConfigUtils {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
|
||||
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry,
|
||||
@Nullable Object source) {
|
||||
|
||||
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
|
||||
|
||||
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
|
||||
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
|
||||
|
@ -119,6 +134,7 @@ public abstract class AopConfigUtils {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
|
||||
beanDefinition.setSource(source);
|
||||
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
|
||||
|
@ -131,7 +147,7 @@ public abstract class AopConfigUtils {
|
|||
return APC_PRIORITY_LIST.indexOf(clazz);
|
||||
}
|
||||
|
||||
private static int findPriorityForClass(String className) {
|
||||
private static int findPriorityForClass(@Nullable String className) {
|
||||
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
|
||||
Class<?> clazz = APC_PRIORITY_LIST.get(i);
|
||||
if (clazz.getName().equals(className)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
|||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Utility class for handling registration of auto-proxy creators used internally
|
||||
|
@ -79,7 +80,7 @@ public abstract class AopNamespaceUtils {
|
|||
registerComponentIfNecessary(beanDefinition, parserContext);
|
||||
}
|
||||
|
||||
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
|
||||
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, @Nullable Element sourceElement) {
|
||||
if (sourceElement != null) {
|
||||
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
|
||||
if (proxyTargetClass) {
|
||||
|
@ -92,7 +93,7 @@ public abstract class AopNamespaceUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static void registerComponentIfNecessary(BeanDefinition beanDefinition, ParserContext parserContext) {
|
||||
private static void registerComponentIfNecessary(@Nullable BeanDefinition beanDefinition, ParserContext parserContext) {
|
||||
if (beanDefinition != null) {
|
||||
BeanComponentDefinition componentDefinition =
|
||||
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.aop.config;
|
|||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanReference;
|
||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.beans.factory.parsing.ComponentDefinition}
|
||||
|
@ -37,8 +38,8 @@ public class AspectComponentDefinition extends CompositeComponentDefinition {
|
|||
private final BeanReference[] beanReferences;
|
||||
|
||||
|
||||
public AspectComponentDefinition(
|
||||
String aspectName, BeanDefinition[] beanDefinitions, BeanReference[] beanReferences, Object source) {
|
||||
public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions,
|
||||
@Nullable BeanReference[] beanReferences, @Nullable Object source) {
|
||||
|
||||
super(aspectName, source);
|
||||
this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -124,7 +124,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (this.proxyClassLoader == null) {
|
||||
this.proxyClassLoader = classLoader;
|
||||
}
|
||||
|
@ -170,8 +170,10 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
|||
}
|
||||
else if (!isProxyTargetClass()) {
|
||||
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
||||
proxyFactory.setInterfaces(
|
||||
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
|
||||
Class<?> targetClass = targetSource.getTargetClass();
|
||||
if (targetClass != null) {
|
||||
proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
|
||||
}
|
||||
}
|
||||
|
||||
postProcessProxyFactory(proxyFactory);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -38,6 +38,7 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
|||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.target.EmptyTargetSource;
|
||||
import org.springframework.aop.target.SingletonTargetSource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
@ -137,7 +138,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setTargetSource(TargetSource targetSource) {
|
||||
public void setTargetSource(@Nullable TargetSource targetSource) {
|
||||
this.targetSource = (targetSource != null ? targetSource : EMPTY_TARGET_SOURCE);
|
||||
}
|
||||
|
||||
|
@ -446,7 +447,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
|||
* @param advice the advice to check inclusion of
|
||||
* @return whether this advice instance is included
|
||||
*/
|
||||
public boolean adviceIncluded(Advice advice) {
|
||||
public boolean adviceIncluded(@Nullable Advice advice) {
|
||||
if (advice != null) {
|
||||
for (Advisor advisor : this.advisors) {
|
||||
if (advisor.getAdvice() == advice) {
|
||||
|
@ -462,7 +463,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
|||
* @param adviceClass the advice class to check
|
||||
* @return the count of the interceptors of this class or subclasses
|
||||
*/
|
||||
public int countAdvicesOfType(Class<?> adviceClass) {
|
||||
public int countAdvicesOfType(@Nullable Class<?> adviceClass) {
|
||||
int count = 0;
|
||||
if (adviceClass != null) {
|
||||
for (Advisor advisor : this.advisors) {
|
||||
|
@ -482,7 +483,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
|||
* @param targetClass the target class
|
||||
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||
*/
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, Class<?> targetClass) {
|
||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
|
||||
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
||||
List<Object> cached = this.methodCache.get(cacheKey);
|
||||
if (cached == null) {
|
||||
|
|
|
@ -134,7 +134,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
* @param constructorArgs the constructor argument values
|
||||
* @param constructorArgTypes the constructor argument types
|
||||
*/
|
||||
public void setConstructorArguments(Object[] constructorArgs, Class<?>[] constructorArgTypes) {
|
||||
public void setConstructorArguments(@Nullable Object[] constructorArgs, @Nullable Class<?>[] constructorArgTypes) {
|
||||
if (constructorArgs == null || constructorArgTypes == null) {
|
||||
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
* Checks to see whether the supplied {@code Class} has already been validated and
|
||||
* validates it if not.
|
||||
*/
|
||||
private void validateClassIfNecessary(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
|
||||
private void validateClassIfNecessary(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
synchronized (validatedClasses) {
|
||||
if (!validatedClasses.containsKey(proxySuperClass)) {
|
||||
|
@ -249,7 +249,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
* Checks for final methods on the given {@code Class}, as well as package-visible
|
||||
* methods across ClassLoaders, and writes warnings to the log for each one found.
|
||||
*/
|
||||
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
|
||||
private void doValidateClass(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
|
||||
if (proxySuperClass != Object.class) {
|
||||
Method[] methods = proxySuperClass.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
|
@ -374,7 +374,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
|
||||
*/
|
||||
@Nullable
|
||||
private static Object processReturnType(Object proxy, Object target, Method method, @Nullable Object retVal) {
|
||||
private static Object processReturnType(Object proxy, @Nullable Object target, Method method, @Nullable Object retVal) {
|
||||
// Massage return value if necessary
|
||||
if (retVal != null && retVal == target &&
|
||||
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
|
||||
|
@ -409,11 +409,12 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final Object target;
|
||||
|
||||
public StaticUnadvisedInterceptor(Object target) {
|
||||
public StaticUnadvisedInterceptor(@Nullable Object target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object retVal = methodProxy.invoke(this.target, args);
|
||||
return processReturnType(proxy, this.target, method, retVal);
|
||||
|
@ -429,11 +430,12 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final Object target;
|
||||
|
||||
public StaticUnadvisedExposedInterceptor(Object target) {
|
||||
public StaticUnadvisedExposedInterceptor(@Nullable Object target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
try {
|
||||
|
@ -462,6 +464,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object target = this.targetSource.getTarget();
|
||||
try {
|
||||
|
@ -469,7 +472,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
return processReturnType(proxy, target, method, retVal);
|
||||
}
|
||||
finally {
|
||||
this.targetSource.releaseTarget(target);
|
||||
if (target != null) {
|
||||
this.targetSource.releaseTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -487,6 +492,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
Object target = this.targetSource.getTarget();
|
||||
|
@ -497,7 +503,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
finally {
|
||||
AopContext.setCurrentProxy(oldProxy);
|
||||
this.targetSource.releaseTarget(target);
|
||||
if (target != null) {
|
||||
this.targetSource.releaseTarget(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -512,7 +520,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private Object target;
|
||||
|
||||
public StaticDispatcher(Object target) {
|
||||
public StaticDispatcher(@Nullable Object target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
@ -604,13 +612,16 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final Class<?> targetClass;
|
||||
|
||||
public FixedChainStaticTargetInterceptor(List<Object> adviceChain, Object target, Class<?> targetClass) {
|
||||
public FixedChainStaticTargetInterceptor(
|
||||
List<Object> adviceChain, @Nullable Object target, @Nullable Class<?> targetClass) {
|
||||
|
||||
this.adviceChain = adviceChain;
|
||||
this.target = target;
|
||||
this.targetClass = targetClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
|
||||
this.targetClass, this.adviceChain, methodProxy);
|
||||
|
@ -635,6 +646,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||
Object oldProxy = null;
|
||||
boolean setProxyContext = false;
|
||||
|
@ -697,6 +709,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
return this.advised.hashCode();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Object getTarget() throws Exception {
|
||||
return this.advised.getTargetSource().getTarget();
|
||||
}
|
||||
|
@ -716,8 +729,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final boolean publicMethod;
|
||||
|
||||
public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments,
|
||||
Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
|
||||
public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method,
|
||||
Object[] arguments, @Nullable Class<?> targetClass,
|
||||
List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
|
||||
|
||||
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
|
||||
this.methodProxy = methodProxy;
|
||||
|
@ -751,7 +765,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final int fixedInterceptorOffset;
|
||||
|
||||
public ProxyCallbackFilter(AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
||||
public ProxyCallbackFilter(
|
||||
AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
||||
|
||||
this.advised = advised;
|
||||
this.fixedInterceptorMap = fixedInterceptorMap;
|
||||
this.fixedInterceptorOffset = fixedInterceptorOffset;
|
||||
|
@ -859,7 +875,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
return INVOKE_TARGET;
|
||||
}
|
||||
Class<?> returnType = method.getReturnType();
|
||||
if (returnType.isAssignableFrom(targetClass)) {
|
||||
if (targetClass != null && returnType.isAssignableFrom(targetClass)) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Method return type is assignable from target type and " +
|
||||
"may therefore return 'this' - using INVOKE_TARGET: " + method);
|
||||
|
@ -886,9 +902,6 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
ProxyCallbackFilter otherCallbackFilter = (ProxyCallbackFilter) other;
|
||||
AdvisedSupport otherAdvised = otherCallbackFilter.advised;
|
||||
if (this.advised == null || otherAdvised == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.advised.isFrozen() != otherAdvised.isFrozen()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -922,12 +935,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
}
|
||||
|
||||
private boolean equalsAdviceClasses(Advisor a, Advisor b) {
|
||||
Advice aa = a.getAdvice();
|
||||
Advice ba = b.getAdvice();
|
||||
if (aa == null || ba == null) {
|
||||
return (aa == ba);
|
||||
}
|
||||
return (aa.getClass() == ba.getClass());
|
||||
return (a.getAdvice().getClass() == b.getAdvice().getClass());
|
||||
}
|
||||
|
||||
private boolean equalsPointcuts(Advisor a, Advisor b) {
|
||||
|
@ -944,9 +952,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
Advisor[] advisors = this.advised.getAdvisors();
|
||||
for (Advisor advisor : advisors) {
|
||||
Advice advice = advisor.getAdvice();
|
||||
if (advice != null) {
|
||||
hashCode = 13 * hashCode + advice.getClass().hashCode();
|
||||
}
|
||||
hashCode = 13 * hashCode + advice.getClass().hashCode();
|
||||
}
|
||||
hashCode = 13 * hashCode + (this.advised.isFrozen() ? 1 : 0);
|
||||
hashCode = 13 * hashCode + (this.advised.isExposeProxy() ? 1 : 0);
|
||||
|
@ -966,7 +972,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public ClassLoaderAwareUndeclaredThrowableStrategy(ClassLoader classLoader) {
|
||||
public ClassLoaderAwareUndeclaredThrowableStrategy(@Nullable ClassLoader classLoader) {
|
||||
super(UndeclaredThrowableException.class);
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -152,6 +152,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
|||
* unless a hook method throws an exception.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
MethodInvocation invocation;
|
||||
Object oldProxy = null;
|
||||
|
@ -249,7 +250,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
|||
* or a dynamic proxy wrapping a JdkDynamicAopProxy instance.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -220,7 +220,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (!this.classLoaderConfigured) {
|
||||
this.proxyClassLoader = classLoader;
|
||||
}
|
||||
|
@ -345,8 +345,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
|||
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
|
||||
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
|
||||
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
||||
copy.setInterfaces(
|
||||
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
|
||||
Class<?> targetClass = targetSource.getTargetClass();
|
||||
if (targetClass != null) {
|
||||
copy.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
|
||||
}
|
||||
}
|
||||
copy.setFrozen(this.freezeProxy);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -69,7 +69,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
|
|||
* {@link org.springframework.beans.factory.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);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (!this.classLoaderConfigured) {
|
||||
this.proxyClassLoader = classLoader;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -103,8 +103,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
|||
* but would complicate the code. And it would work only for static pointcuts.
|
||||
*/
|
||||
protected ReflectiveMethodInvocation(
|
||||
Object proxy, Object target, Method method, Object[] arguments,
|
||||
Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
||||
Object proxy, @Nullable Object target, Method method, Object[] arguments,
|
||||
@Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
||||
|
||||
this.proxy = proxy;
|
||||
this.target = target;
|
||||
|
@ -152,6 +152,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object proceed() throws Throwable {
|
||||
// We start with an index of -1 and increment early.
|
||||
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
|
||||
|
@ -187,6 +188,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
|||
* @return the return value of the joinpoint
|
||||
* @throws Throwable if invoking the joinpoint resulted in an exception
|
||||
*/
|
||||
@Nullable
|
||||
protected Object invokeJoinpoint() throws Throwable {
|
||||
return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);
|
||||
}
|
||||
|
@ -220,7 +222,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
|||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public MethodInvocation invocableClone(Object... arguments) {
|
||||
public MethodInvocation invocableClone(@Nullable Object... arguments) {
|
||||
// Force initialization of the user attributes Map,
|
||||
// for having a shared Map reference in the clone.
|
||||
if (this.userAttributes == null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.AfterAdvice;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -103,6 +104,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
|||
* @param exception the exception thrown
|
||||
* @return a handler for the given exception type
|
||||
*/
|
||||
@Nullable
|
||||
private Method getExceptionHandler(Throwable exception) {
|
||||
Class<?> exceptionClass = exception.getClass();
|
||||
if (logger.isTraceEnabled()) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -238,7 +238,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
|
||||
public Object postProcessBeforeInstantiation(Class<?> beanClass, @Nullable String beanName) throws BeansException {
|
||||
Object cacheKey = getCacheKey(beanClass, beanName);
|
||||
|
||||
if (beanName == null || !this.targetSourcedBeans.contains(beanName)) {
|
||||
|
@ -291,7 +291,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @see #getAdvicesAndAdvisorsForBean
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) throws BeansException {
|
||||
if (bean != null) {
|
||||
Object cacheKey = getCacheKey(bean.getClass(), beanName);
|
||||
if (!this.earlyProxyReferences.contains(cacheKey)) {
|
||||
|
@ -313,7 +313,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @param beanName the bean name
|
||||
* @return the cache key for the given class and name
|
||||
*/
|
||||
protected Object getCacheKey(Class<?> beanClass, String beanName) {
|
||||
protected Object getCacheKey(Class<?> beanClass, @Nullable String beanName) {
|
||||
if (StringUtils.hasLength(beanName)) {
|
||||
return (FactoryBean.class.isAssignableFrom(beanClass) ?
|
||||
BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
|
||||
|
@ -330,7 +330,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @param cacheKey the cache key for metadata access
|
||||
* @return a proxy wrapping the bean, or the raw bean instance as-is
|
||||
*/
|
||||
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
|
||||
protected Object wrapIfNecessary(Object bean, @Nullable String beanName, Object cacheKey) {
|
||||
if (beanName != null && this.targetSourcedBeans.contains(beanName)) {
|
||||
return bean;
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @param beanName the name of the bean
|
||||
* @return whether to skip the given bean
|
||||
*/
|
||||
protected boolean shouldSkip(Class<?> beanClass, String beanName) {
|
||||
protected boolean shouldSkip(Class<?> beanClass, @Nullable String beanName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -435,8 +435,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @return the AOP proxy for the bean
|
||||
* @see #buildAdvisors
|
||||
*/
|
||||
protected Object createProxy(
|
||||
Class<?> beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) {
|
||||
protected Object createProxy(Class<?> beanClass, @Nullable String beanName,
|
||||
@Nullable Object[] specificInterceptors, TargetSource targetSource) {
|
||||
|
||||
if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
|
||||
AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass);
|
||||
|
@ -479,7 +479,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @return whether the given bean should be proxied with its target class
|
||||
* @see AutoProxyUtils#shouldProxyTargetClass
|
||||
*/
|
||||
protected boolean shouldProxyTargetClass(Class<?> beanClass, String beanName) {
|
||||
protected boolean shouldProxyTargetClass(Class<?> beanClass, @Nullable String beanName) {
|
||||
return (this.beanFactory instanceof ConfigurableListableBeanFactory &&
|
||||
AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName));
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* specific to this bean (may be empty, but not null)
|
||||
* @return the list of Advisors for the given bean
|
||||
*/
|
||||
protected Advisor[] buildAdvisors(String beanName, Object[] specificInterceptors) {
|
||||
protected Advisor[] buildAdvisors(@Nullable String beanName, @Nullable Object[] specificInterceptors) {
|
||||
// Handle prototypes correctly...
|
||||
Advisor[] commonInterceptors = resolveInterceptorNames();
|
||||
|
||||
|
@ -582,7 +582,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
|||
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract Object[] getAdvicesAndAdvisorsForBean(
|
||||
Class<?> beanClass, String beanName, @Nullable TargetSource customTargetSource) throws BeansException;
|
||||
protected abstract Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass,
|
||||
@Nullable String beanName, @Nullable TargetSource customTargetSource)
|
||||
throws BeansException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -63,7 +63,7 @@ public abstract class AutoProxyUtils {
|
|||
* @param beanName the name of the bean
|
||||
* @return whether the given bean should be proxied with its target class
|
||||
*/
|
||||
public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
|
||||
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
||||
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
|
||||
return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
|
||||
|
@ -81,7 +81,7 @@ public abstract class AutoProxyUtils {
|
|||
* @see org.springframework.beans.factory.BeanFactory#getType(String)
|
||||
*/
|
||||
@Nullable
|
||||
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
|
||||
if (beanName == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -102,7 +102,9 @@ public abstract class AutoProxyUtils {
|
|||
* @param targetClass the corresponding target class
|
||||
* @since 4.2.3
|
||||
*/
|
||||
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName, Class<?> targetClass) {
|
||||
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName,
|
||||
Class<?> targetClass) {
|
||||
|
||||
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
||||
beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,6 +20,8 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Base class for monitoring interceptors, such as performance monitors.
|
||||
* Provides {@code prefix} and {@code suffix} properties
|
||||
|
@ -50,7 +52,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
|||
* Set the text that will get appended to the trace data.
|
||||
* <p>Default is none.
|
||||
*/
|
||||
public void setPrefix(String prefix) {
|
||||
public void setPrefix(@Nullable String prefix) {
|
||||
this.prefix = (prefix != null ? prefix : "");
|
||||
}
|
||||
|
||||
|
@ -65,7 +67,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
|||
* Set the text that will get prepended to the trace data.
|
||||
* <p>Default is none.
|
||||
*/
|
||||
public void setSuffix(String suffix) {
|
||||
public void setSuffix(@Nullable String suffix) {
|
||||
this.suffix = (suffix != null ? suffix : "");
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
* executor has been requested via a qualifier on the async method, in which case the
|
||||
* executor will be looked up at invocation time against the enclosing bean factory
|
||||
*/
|
||||
public AsyncExecutionAspectSupport(Executor defaultExecutor) {
|
||||
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor) {
|
||||
this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
* executor will be looked up at invocation time against the enclosing bean factory
|
||||
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
||||
*/
|
||||
public AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||
this.defaultExecutor = defaultExecutor;
|
||||
this.exceptionHandler = exceptionHandler;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
* @see #getExecutorQualifier(Method)
|
||||
*/
|
||||
@Nullable
|
||||
protected Executor findQualifiedExecutor(BeanFactory beanFactory, String qualifier) {
|
||||
protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) {
|
||||
if (beanFactory == null) {
|
||||
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
|
||||
" to access qualified executor '" + qualifier + "'");
|
||||
|
@ -217,7 +217,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
|||
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
|
||||
*/
|
||||
@Nullable
|
||||
protected Executor getDefaultExecutor(BeanFactory beanFactory) {
|
||||
protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
|
||||
if (beanFactory != null) {
|
||||
try {
|
||||
// Search for TaskExecutor bean... not plain Executor since that would
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -31,6 +31,7 @@ import org.springframework.core.BridgeMethodResolver;
|
|||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.task.AsyncTaskExecutor;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
|
@ -73,7 +74,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
|||
* or {@link java.util.concurrent.ExecutorService}) to delegate to;
|
||||
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
||||
*/
|
||||
public AsyncExecutionInterceptor(Executor defaultExecutor) {
|
||||
public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor) {
|
||||
super(defaultExecutor);
|
||||
}
|
||||
|
||||
|
@ -84,7 +85,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
|||
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
||||
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
||||
*/
|
||||
public AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||
public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||
super(defaultExecutor, exceptionHandler);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -292,7 +292,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
|||
* at {@code TRACE} level. Sub-classes can override this method
|
||||
* to control which level the message is written at.
|
||||
*/
|
||||
protected void writeToLog(Log logger, String message, Throwable ex) {
|
||||
protected void writeToLog(Log logger, String message, @Nullable Throwable ex) {
|
||||
if (ex != null) {
|
||||
logger.trace(message, ex);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
|||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Utility class for creating a scoped proxy.
|
||||
|
@ -102,7 +103,7 @@ public abstract class ScopedProxyUtils {
|
|||
* bean within a scoped proxy.
|
||||
* @since 4.1.4
|
||||
*/
|
||||
public static boolean isScopedTarget(String beanName) {
|
||||
public static boolean isScopedTarget(@Nullable String beanName) {
|
||||
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -101,11 +101,13 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
|
|||
@Override
|
||||
public Advice getAdvice() {
|
||||
Advice advice = this.advice;
|
||||
if (advice != null || this.adviceBeanName == null) {
|
||||
if (advice != null) {
|
||||
return advice;
|
||||
}
|
||||
|
||||
Assert.state(this.adviceBeanName != null, "'adviceBeanName' must be specified");
|
||||
Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'");
|
||||
|
||||
if (this.beanFactory.isSingleton(this.adviceBeanName)) {
|
||||
// Rely on singleton semantics provided by the factory.
|
||||
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -127,7 +127,10 @@ public abstract class AopUtils {
|
|||
* @since 4.3
|
||||
* @see MethodIntrospector#selectInvocableMethod(Method, Class)
|
||||
*/
|
||||
public static Method selectInvocableMethod(Method method, Class<?> targetType) {
|
||||
public static Method selectInvocableMethod(Method method, @Nullable Class<?> targetType) {
|
||||
if (targetType == null) {
|
||||
return method;
|
||||
}
|
||||
Method methodToUse = MethodIntrospector.selectInvocableMethod(method, targetType);
|
||||
if (Modifier.isPrivate(methodToUse.getModifiers()) && !Modifier.isStatic(methodToUse.getModifiers()) &&
|
||||
SpringProxy.class.isAssignableFrom(targetType)) {
|
||||
|
@ -143,7 +146,7 @@ public abstract class AopUtils {
|
|||
* Determine whether the given method is an "equals" method.
|
||||
* @see java.lang.Object#equals
|
||||
*/
|
||||
public static boolean isEqualsMethod(Method method) {
|
||||
public static boolean isEqualsMethod(@Nullable Method method) {
|
||||
return ReflectionUtils.isEqualsMethod(method);
|
||||
}
|
||||
|
||||
|
@ -151,7 +154,7 @@ public abstract class AopUtils {
|
|||
* Determine whether the given method is a "hashCode" method.
|
||||
* @see java.lang.Object#hashCode
|
||||
*/
|
||||
public static boolean isHashCodeMethod(Method method) {
|
||||
public static boolean isHashCodeMethod(@Nullable Method method) {
|
||||
return ReflectionUtils.isHashCodeMethod(method);
|
||||
}
|
||||
|
||||
|
@ -159,7 +162,7 @@ public abstract class AopUtils {
|
|||
* Determine whether the given method is a "toString" method.
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public static boolean isToStringMethod(Method method) {
|
||||
public static boolean isToStringMethod(@Nullable Method method) {
|
||||
return ReflectionUtils.isToStringMethod(method);
|
||||
}
|
||||
|
||||
|
@ -167,7 +170,7 @@ public abstract class AopUtils {
|
|||
* Determine whether the given method is a "finalize" method.
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
public static boolean isFinalizeMethod(Method method) {
|
||||
public static boolean isFinalizeMethod(@Nullable Method method) {
|
||||
return (method != null && method.getName().equals("finalize") &&
|
||||
method.getParameterCount() == 0);
|
||||
}
|
||||
|
@ -326,7 +329,7 @@ public abstract class AopUtils {
|
|||
* @throws org.springframework.aop.AopInvocationException in case of a reflection error
|
||||
*/
|
||||
@Nullable
|
||||
public static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args)
|
||||
public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args)
|
||||
throws Throwable {
|
||||
|
||||
// Use reflection to invoke the method.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.aop.support;
|
||||
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Concrete BeanFactory-based PointcutAdvisor that allows for any Advice
|
||||
|
@ -43,7 +44,7 @@ public class DefaultBeanFactoryPointcutAdvisor extends AbstractBeanFactoryPointc
|
|||
* <p>Default is {@code Pointcut.TRUE}.
|
||||
* @see #setAdviceBeanName
|
||||
*/
|
||||
public void setPointcut(Pointcut pointcut) {
|
||||
public void setPointcut(@Nullable Pointcut pointcut) {
|
||||
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,6 +21,7 @@ import java.io.Serializable;
|
|||
import org.aopalliance.aop.Advice;
|
||||
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Convenient Pointcut-driven Advisor implementation.
|
||||
|
@ -73,7 +74,7 @@ public class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor imple
|
|||
* <p>Default is {@code Pointcut.TRUE}.
|
||||
* @see #setAdvice
|
||||
*/
|
||||
public void setPointcut(Pointcut pointcut) {
|
||||
public void setPointcut(@Nullable Pointcut pointcut) {
|
||||
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.aop.support;
|
||||
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by pointcuts that use String expressions.
|
||||
|
@ -29,6 +30,7 @@ public interface ExpressionPointcut extends Pointcut {
|
|||
/**
|
||||
* Return the String expression for this pointcut.
|
||||
*/
|
||||
@Nullable
|
||||
String getExpression();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -125,11 +125,11 @@ public abstract class MethodMatchers {
|
|||
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
|
||||
}
|
||||
|
||||
protected boolean matchesClass1(Class<?> targetClass) {
|
||||
protected boolean matchesClass1(@Nullable Class<?> targetClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean matchesClass2(Class<?> targetClass) {
|
||||
protected boolean matchesClass2(@Nullable Class<?> targetClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -183,13 +183,13 @@ public abstract class MethodMatchers {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesClass1(Class<?> targetClass) {
|
||||
return this.cf1.matches(targetClass);
|
||||
protected boolean matchesClass1(@Nullable Class<?> targetClass) {
|
||||
return (targetClass != null && this.cf1.matches(targetClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean matchesClass2(Class<?> targetClass) {
|
||||
return this.cf2.matches(targetClass);
|
||||
protected boolean matchesClass2(@Nullable Class<?> targetClass) {
|
||||
return (targetClass != null && this.cf2.matches(targetClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -56,7 +56,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
|||
* Matching will be the union of all these; if any match,
|
||||
* the pointcut matches.
|
||||
*/
|
||||
public void setMappedNames(String... mappedNames) {
|
||||
public void setMappedNames(@Nullable String... mappedNames) {
|
||||
this.mappedNames = new LinkedList<>();
|
||||
if (mappedNames != null) {
|
||||
this.mappedNames.addAll(Arrays.asList(mappedNames));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,7 +21,6 @@ import java.io.Serializable;
|
|||
import org.aopalliance.aop.Advice;
|
||||
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
|
@ -133,7 +132,6 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
|
|||
* will be used.
|
||||
* @return the Pointcut instance (never {@code null})
|
||||
*/
|
||||
@Nullable
|
||||
protected AbstractRegexpMethodPointcut createPointcut() {
|
||||
return new JdkRegexpMethodPointcut();
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
|||
* @param methodAnnotationType the annotation type to look for at the method level
|
||||
* (can be {@code null})
|
||||
*/
|
||||
public AnnotationMatchingPointcut(
|
||||
@Nullable Class<? extends Annotation> classAnnotationType, @Nullable Class<? extends Annotation> methodAnnotationType) {
|
||||
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
|
||||
@Nullable Class<? extends Annotation> methodAnnotationType) {
|
||||
|
||||
this(classAnnotationType, methodAnnotationType, false);
|
||||
}
|
||||
|
@ -87,8 +87,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
|||
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
|
||||
* @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
|
||||
*/
|
||||
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType,
|
||||
Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {
|
||||
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
|
||||
@Nullable Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {
|
||||
|
||||
Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
|
||||
"Either Class annotation type or Method annotation type needs to be specified (or both)");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
|
@ -129,9 +130,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
|||
logger.trace("Getting bean with name '" + this.targetBeanName + "' in order to determine type");
|
||||
}
|
||||
Object beanInstance = this.beanFactory.getBean(this.targetBeanName);
|
||||
if (beanInstance != null) {
|
||||
this.targetClass = beanInstance.getClass();
|
||||
}
|
||||
this.targetClass = beanInstance.getClass();
|
||||
}
|
||||
}
|
||||
return this.targetClass;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<cache:annotation-driven mode="aspectj" key-generator="keyGenerator"/>
|
||||
|
||||
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator" />
|
||||
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator"/>
|
||||
|
||||
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||
<property name="caches">
|
||||
|
@ -40,7 +40,7 @@
|
|||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="customKeyGenerator" class="org.springframework.cache.config.SomeCustomKeyGenerator" />
|
||||
<bean id="customKeyGenerator" class="org.springframework.cache.config.SomeCustomKeyGenerator"/>
|
||||
|
||||
<bean id="customCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||
<property name="caches">
|
||||
|
@ -55,6 +55,7 @@
|
|||
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
|
||||
|
||||
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
|
||||
|
||||
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -257,7 +257,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
|||
|
||||
int countBefore = getRegistry().getBeanDefinitionCount();
|
||||
try {
|
||||
GroovyShell shell = new GroovyShell(getResourceLoader().getClassLoader(), binding);
|
||||
GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
|
||||
shell.evaluate(encodedResource.getReader(), "beans");
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -56,10 +56,10 @@ import org.springframework.util.StringUtils;
|
|||
* as String arrays are converted in such a format if the array itself is not
|
||||
* assignable.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Stephane Nicoll
|
||||
* @author Rod Johnson
|
||||
* @author Rob Harrop
|
||||
* @since 4.2
|
||||
* @see #registerCustomEditor
|
||||
* @see #setPropertyValues
|
||||
|
@ -189,7 +189,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
* @param nestedPath the nested path of the object
|
||||
* @param rootObject the root object at the top of the path
|
||||
*/
|
||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
||||
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
||||
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||
|
@ -199,11 +199,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
|
||||
public final Object getWrappedInstance() {
|
||||
Assert.state(this.wrappedObject != null, "No wrapped instance");
|
||||
return this.wrappedObject;
|
||||
}
|
||||
|
||||
public final Class<?> getWrappedClass() {
|
||||
return (this.wrappedObject != null ? this.wrappedObject.getClass() : null);
|
||||
return getWrappedInstance().getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +218,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
* Return the root object at the top of the path of this accessor.
|
||||
* @see #getNestedPath
|
||||
*/
|
||||
@Nullable
|
||||
public final Object getRootInstance() {
|
||||
return this.rootObject;
|
||||
}
|
||||
|
@ -226,11 +228,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
* @see #getNestedPath
|
||||
*/
|
||||
public final Class<?> getRootClass() {
|
||||
return (this.rootObject != null ? this.rootObject.getClass() : null);
|
||||
Assert.state(this.wrappedObject != null, "No root object");
|
||||
return this.rootObject.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPropertyValue(String propertyName, Object value) throws BeansException {
|
||||
public void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException {
|
||||
AbstractNestablePropertyAccessor nestedPa;
|
||||
try {
|
||||
nestedPa = getPropertyAccessorForPropertyPath(propertyName);
|
||||
|
@ -279,10 +282,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
@SuppressWarnings("unchecked")
|
||||
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
|
||||
Object propValue = getPropertyHoldingValue(tokens);
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
if (ph == null) {
|
||||
throw new InvalidPropertyException(
|
||||
getRootClass(), this.nestedPath + tokens.actualName, "No property handler found");
|
||||
}
|
||||
String lastKey = tokens.keys[tokens.keys.length - 1];
|
||||
|
||||
if (propValue.getClass().isArray()) {
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
Class<?> requiredType = propValue.getClass().getComponentType();
|
||||
int arrayIndex = Integer.parseInt(lastKey);
|
||||
Object oldValue = null;
|
||||
|
@ -309,7 +316,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
|
||||
else if (propValue instanceof List) {
|
||||
PropertyHandler ph = getPropertyHandler(tokens.actualName);
|
||||
Class<?> requiredType = ph.getCollectionType(tokens.keys.length);
|
||||
List<Object> list = (List<Object>) propValue;
|
||||
int index = Integer.parseInt(lastKey);
|
||||
|
@ -346,7 +352,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
|
||||
else if (propValue instanceof Map) {
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length);
|
||||
Class<?> mapValueType = ph.getMapValueType(tokens.keys.length);
|
||||
Map<Object, Object> map = (Map<Object, Object>) propValue;
|
||||
|
@ -449,7 +454,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
|
||||
}
|
||||
ph.setValue(this.wrappedObject, valueToApply);
|
||||
ph.setValue(valueToApply);
|
||||
}
|
||||
catch (TypeMismatchException ex) {
|
||||
throw ex;
|
||||
|
@ -567,34 +572,29 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
return false;
|
||||
}
|
||||
|
||||
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, Class<?> requiredType,
|
||||
TypeDescriptor td) throws TypeMismatchException {
|
||||
@Nullable
|
||||
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||
@Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable TypeDescriptor td)
|
||||
throws TypeMismatchException {
|
||||
|
||||
try {
|
||||
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
|
||||
}
|
||||
catch (ConverterNotFoundException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new ConversionNotSupportedException(pce, td.getType(), ex);
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new TypeMismatchException(pce, requiredType, ex);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new ConversionNotSupportedException(pce, requiredType, ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConversionException | IllegalArgumentException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new TypeMismatchException(pce, requiredType, ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object convertForProperty(String propertyName, @Nullable Object oldValue, Object newValue, TypeDescriptor td)
|
||||
@Nullable
|
||||
protected Object convertForProperty(
|
||||
String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
|
||||
|
@ -608,6 +608,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
||||
String propertyName = tokens.canonicalName;
|
||||
String actualName = tokens.actualName;
|
||||
|
@ -724,10 +725,10 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a {@link PropertyHandler} for the specified local {@code propertyName}. Only
|
||||
* used to reach a property available in the current context.
|
||||
* Return a {@link PropertyHandler} for the specified local {@code propertyName}.
|
||||
* Only used to reach a property available in the current context.
|
||||
* @param propertyName the name of a local property
|
||||
* @return the handler for that property or {@code null} if it has not been found
|
||||
* @return the handler for that property, or {@code null} if it has not been found
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
|
||||
|
@ -760,7 +761,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
Array.set(newArray, i, newValue(componentType, null, name));
|
||||
}
|
||||
setPropertyValue(name, newArray);
|
||||
return getPropertyValue(name);
|
||||
Object defaultValue = getPropertyValue(name);
|
||||
Assert.state(defaultValue != null, "Default value must not be null");
|
||||
return defaultValue;
|
||||
}
|
||||
else {
|
||||
return array;
|
||||
|
@ -872,17 +875,18 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
private Object setDefaultValue(PropertyTokenHolder tokens) {
|
||||
PropertyValue pv = createDefaultPropertyValue(tokens);
|
||||
setPropertyValue(tokens, pv);
|
||||
return getPropertyValue(tokens);
|
||||
Object defaultValue = getPropertyValue(tokens);
|
||||
Assert.state(defaultValue != null, "Default value must not be null");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private PropertyValue createDefaultPropertyValue(PropertyTokenHolder tokens) {
|
||||
TypeDescriptor desc = getPropertyTypeDescriptor(tokens.canonicalName);
|
||||
Class<?> type = desc.getType();
|
||||
if (type == null) {
|
||||
if (desc == null) {
|
||||
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
|
||||
"Could not determine property type for auto-growing a default value");
|
||||
}
|
||||
Object defaultValue = newValue(type, desc, tokens.canonicalName);
|
||||
Object defaultValue = newValue(desc.getType(), desc, tokens.canonicalName);
|
||||
return new PropertyValue(tokens.canonicalName, defaultValue);
|
||||
}
|
||||
|
||||
|
@ -1005,24 +1009,28 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
|
||||
public abstract ResolvableType getResolvableType();
|
||||
|
||||
@Nullable
|
||||
public Class<?> getMapKeyType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> getMapValueType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> getCollectionType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract TypeDescriptor nested(int level);
|
||||
|
||||
@Nullable
|
||||
public abstract Object getValue() throws Exception;
|
||||
|
||||
public abstract void setValue(Object object, Object value) throws Exception;
|
||||
public abstract void setValue(@Nullable Object value) throws Exception;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,6 +21,8 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the {@link PropertyAccessor} interface.
|
||||
* Provides base implementations of all convenience methods, with the
|
||||
|
@ -151,6 +153,6 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
|||
* accessor method failed or a type mismatch occurred
|
||||
*/
|
||||
@Override
|
||||
public abstract void setPropertyValue(String propertyName, Object value) throws BeansException;
|
||||
public abstract void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -53,7 +53,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeanInstantiationException(Class<?> beanClass, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Class<?> beanClass, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
|
||||
this.beanClass = beanClass;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
|||
* @param cause the root cause
|
||||
* @since 4.3
|
||||
*/
|
||||
public BeanInstantiationException(Constructor<?> constructor, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Constructor<?> constructor, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructor.getDeclaringClass();
|
||||
this.constructor = constructor;
|
||||
|
@ -79,7 +79,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
|||
* @param cause the root cause
|
||||
* @since 4.3
|
||||
*/
|
||||
public BeanInstantiationException(Method constructingMethod, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructingMethod.getReturnType();
|
||||
this.constructingMethod = constructingMethod;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
|||
* @param name the name of the attribute (never {@code null})
|
||||
* @param value the value of the attribute (possibly before type conversion)
|
||||
*/
|
||||
public BeanMetadataAttribute(String name, Object value) {
|
||||
public BeanMetadataAttribute(String name, @Nullable Object value) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
|
@ -65,7 +66,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
|||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
|
|||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -426,7 +426,7 @@ public abstract class BeanUtils {
|
|||
* @return the corresponding editor, or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
public static PropertyEditor findEditorByConvention(Class<?> targetType) {
|
||||
public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetType) {
|
||||
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ public abstract class BeanUtils {
|
|||
* @param beanClasses the classes to check against
|
||||
* @return the property type, or {@code Object.class} as fallback
|
||||
*/
|
||||
public static Class<?> findPropertyType(String propertyName, Class<?>... beanClasses) {
|
||||
public static Class<?> findPropertyType(String propertyName, @Nullable Class<?>... beanClasses) {
|
||||
if (beanClasses != null) {
|
||||
for (Class<?> beanClass : beanClasses) {
|
||||
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
|
||||
|
@ -599,8 +599,8 @@ public abstract class BeanUtils {
|
|||
* @throws BeansException if the copying failed
|
||||
* @see BeanWrapper
|
||||
*/
|
||||
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, String... ignoreProperties)
|
||||
throws BeansException {
|
||||
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
|
||||
@Nullable String... ignoreProperties) throws BeansException {
|
||||
|
||||
Assert.notNull(source, "Source must not be null");
|
||||
Assert.notNull(target, "Target must not be null");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +18,6 @@ package org.springframework.beans;
|
|||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* The central interface of Spring's low-level JavaBeans infrastructure.
|
||||
*
|
||||
|
@ -64,18 +62,13 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
|
|||
int getAutoGrowCollectionLimit();
|
||||
|
||||
/**
|
||||
* Return the bean instance wrapped by this object, if any.
|
||||
* @return the bean instance, or {@code null} if none set
|
||||
* Return the bean instance wrapped by this object.
|
||||
*/
|
||||
@Nullable
|
||||
Object getWrappedInstance();
|
||||
|
||||
/**
|
||||
* Return the type of the wrapped JavaBean object.
|
||||
* @return the type of the wrapped bean instance,
|
||||
* or {@code null} if no wrapped object has been set
|
||||
* Return the type of the wrapped bean instance.
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getWrappedClass();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.beans;
|
|||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
@ -29,7 +28,7 @@ import org.springframework.core.ResolvableType;
|
|||
import org.springframework.core.convert.Property;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Default {@link BeanWrapper} implementation that should be sufficient
|
||||
|
@ -148,7 +147,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
||||
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||
super.setWrappedInstance(object, nestedPath, rootObject);
|
||||
setIntrospectionClass(getWrappedClass());
|
||||
}
|
||||
|
@ -169,7 +168,6 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
* for the wrapped object.
|
||||
*/
|
||||
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
||||
Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
|
||||
if (this.cachedIntrospectionResults == null) {
|
||||
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
||||
}
|
||||
|
@ -203,6 +201,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
* @return the new value, possibly the result of type conversion
|
||||
* @throws TypeMismatchException if type conversion failed
|
||||
*/
|
||||
@Nullable
|
||||
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
|
||||
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
|
||||
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
|
||||
|
@ -289,73 +288,45 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
|||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
final Method readMethod = this.pd.getReadMethod();
|
||||
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
readMethod.setAccessible(true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
readMethod.setAccessible(true);
|
||||
}
|
||||
}
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(readMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
||||
}
|
||||
}, acc);
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
readMethod.invoke(getWrappedInstance(), (Object[]) null), acc);
|
||||
}
|
||||
catch (PrivilegedActionException pae) {
|
||||
throw pae.getException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReflectionUtils.makeAccessible(readMethod);
|
||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final Object object, Object valueToApply) throws Exception {
|
||||
public void setValue(final @Nullable Object value) throws Exception {
|
||||
final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?
|
||||
((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :
|
||||
this.pd.getWriteMethod());
|
||||
if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers()) && !writeMethod.isAccessible()) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
writeMethod.setAccessible(true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
writeMethod.setAccessible(true);
|
||||
}
|
||||
}
|
||||
final Object value = valueToApply;
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(writeMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
writeMethod.invoke(object, value);
|
||||
return null;
|
||||
}
|
||||
}, acc);
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
writeMethod.invoke(getWrappedInstance(), value), acc);
|
||||
}
|
||||
catch (PrivilegedActionException ex) {
|
||||
throw ex.getException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReflectionUtils.makeAccessible(writeMethod);
|
||||
writeMethod.invoke(getWrappedInstance(), value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract superclass for all exceptions thrown in the beans package
|
||||
|
@ -46,27 +46,8 @@ public abstract class BeansException extends NestedRuntimeException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeansException(String msg, Throwable cause) {
|
||||
public BeansException(@Nullable String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof BeansException)) {
|
||||
return false;
|
||||
}
|
||||
BeansException otherBe = (BeansException) other;
|
||||
return (getMessage().equals(otherBe.getMessage()) &&
|
||||
ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getMessage().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -136,7 +137,7 @@ public class CachedIntrospectionResults {
|
|||
* be paired with a {@link #clearClassLoader} call at application shutdown.
|
||||
* @param classLoader the ClassLoader to accept
|
||||
*/
|
||||
public static void acceptClassLoader(ClassLoader classLoader) {
|
||||
public static void acceptClassLoader(@Nullable ClassLoader classLoader) {
|
||||
if (classLoader != null) {
|
||||
acceptedClassLoaders.add(classLoader);
|
||||
}
|
||||
|
@ -148,7 +149,7 @@ public class CachedIntrospectionResults {
|
|||
* removing the ClassLoader (and its children) from the acceptance list.
|
||||
* @param classLoader the ClassLoader to clear the cache for
|
||||
*/
|
||||
public static void clearClassLoader(ClassLoader classLoader) {
|
||||
public static void clearClassLoader(@Nullable ClassLoader classLoader) {
|
||||
for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = it.next();
|
||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||
|
@ -226,7 +227,7 @@ public class CachedIntrospectionResults {
|
|||
* @param candidate the candidate ClassLoader to check
|
||||
* @param parent the parent ClassLoader to check for
|
||||
*/
|
||||
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
|
||||
private static boolean isUnderneathClassLoader(@Nullable ClassLoader candidate, @Nullable ClassLoader parent) {
|
||||
if (candidate == parent) {
|
||||
return true;
|
||||
}
|
||||
|
@ -336,6 +337,7 @@ public class CachedIntrospectionResults {
|
|||
return this.beanInfo.getBeanDescriptor().getBeanClass();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
PropertyDescriptor getPropertyDescriptor(String name) {
|
||||
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
|
||||
if (pd == null && StringUtils.hasLength(name)) {
|
||||
|
@ -375,6 +377,7 @@ public class CachedIntrospectionResults {
|
|||
return (existing != null ? existing : td);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {
|
||||
return this.typeDescriptorCache.get(pd);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,7 +37,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property
|
|||
* Specify a Spring 3.0 ConversionService to use for converting
|
||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
*/
|
||||
void setConversionService(ConversionService conversionService);
|
||||
void setConversionService(@Nullable ConversionService conversionService);
|
||||
|
||||
/**
|
||||
* Return the associated ConversionService, if any.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -134,10 +134,10 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object object, Object value) throws Exception {
|
||||
public void setValue(Object value) throws Exception {
|
||||
try {
|
||||
ReflectionUtils.makeAccessible(this.field);
|
||||
this.field.set(object, value);
|
||||
this.field.set(getWrappedInstance(), value);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Thrown on an unrecoverable problem encountered in the
|
||||
* beans packages or sub-packages, e.g. bad class or field.
|
||||
|
@ -39,7 +41,7 @@ public class FatalBeanException extends BeansException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public FatalBeanException(String msg, Throwable cause) {
|
||||
public FatalBeanException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -57,18 +58,14 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
|
|||
|
||||
|
||||
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
|
||||
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
|
||||
@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
|
||||
throws IntrospectionException {
|
||||
|
||||
super(propertyName, null, null);
|
||||
|
||||
if (beanClass == null) {
|
||||
throw new IntrospectionException("Bean class must not be null");
|
||||
}
|
||||
this.beanClass = beanClass;
|
||||
|
||||
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
|
||||
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
|
||||
Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
|
||||
Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
|
||||
if (writeMethodToUse == null && readMethodToUse != null) {
|
||||
// Fallback: Original JavaBeans introspection might not have found matching setter
|
||||
// method due to lack of bridge method resolution, in case of the getter using a
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when referring to an invalid bean property.
|
||||
* Carries the offending bean class and property name.
|
||||
|
@ -48,7 +50,7 @@ public class InvalidPropertyException extends FatalBeanException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, Throwable cause) {
|
||||
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, @Nullable Throwable cause) {
|
||||
super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
|
||||
this.beanClass = beanClass;
|
||||
this.propertyName = propertyName;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -62,7 +62,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* @param original the PropertyValues to copy
|
||||
* @see #addPropertyValues(PropertyValues)
|
||||
*/
|
||||
public MutablePropertyValues(PropertyValues original) {
|
||||
public MutablePropertyValues(@Nullable PropertyValues original) {
|
||||
// We can optimize this because it's all new:
|
||||
// There is no replacement of existing property values.
|
||||
if (original != null) {
|
||||
|
@ -82,7 +82,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* @param original Map with property values keyed by property name Strings
|
||||
* @see #addPropertyValues(Map)
|
||||
*/
|
||||
public MutablePropertyValues(Map<?, ?> original) {
|
||||
public MutablePropertyValues(@Nullable Map<?, ?> original) {
|
||||
// We can optimize this because it's all new:
|
||||
// There is no replacement of existing property values.
|
||||
if (original != null) {
|
||||
|
@ -103,7 +103,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* It is not intended for typical programmatic use.
|
||||
* @param propertyValueList List of PropertyValue objects
|
||||
*/
|
||||
public MutablePropertyValues(List<PropertyValue> propertyValueList) {
|
||||
public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) {
|
||||
this.propertyValueList =
|
||||
(propertyValueList != null ? propertyValueList : new ArrayList<>());
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* @param other the PropertyValues to copy
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues addPropertyValues(PropertyValues other) {
|
||||
public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {
|
||||
if (other != null) {
|
||||
PropertyValue[] pvs = other.getPropertyValues();
|
||||
for (PropertyValue pv : pvs) {
|
||||
|
@ -149,7 +149,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* which must be a String
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues addPropertyValues(Map<?, ?> other) {
|
||||
public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {
|
||||
if (other != null) {
|
||||
for (Map.Entry<?, ?> entry : other.entrySet()) {
|
||||
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
|
||||
|
@ -197,7 +197,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
* @param propertyValue value of the property
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues add(String propertyName, Object propertyValue) {
|
||||
public MutablePropertyValues add(String propertyName, @Nullable Object propertyValue) {
|
||||
addPropertyValue(new PropertyValue(propertyName, propertyValue));
|
||||
return this;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
|||
/**
|
||||
* Get the raw property value, if any.
|
||||
* @param propertyName the name to search for
|
||||
* @return the raw property value, or {@code null}
|
||||
* @return the raw property value, or {@code null} if none found
|
||||
* @since 4.0
|
||||
* @see #getPropertyValue(String)
|
||||
* @see PropertyValue#getValue()
|
||||
|
|
|
@ -39,7 +39,7 @@ public abstract class PropertyAccessException extends BeansException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, Throwable cause) {
|
||||
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.propertyChangeEvent = propertyChangeEvent;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public abstract class PropertyAccessException extends BeansException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public PropertyAccessException(String msg, Throwable cause) {
|
||||
public PropertyAccessException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ public abstract class PropertyAccessException extends BeansException {
|
|||
/**
|
||||
* Return the name of the affected property, if available.
|
||||
*/
|
||||
@Nullable
|
||||
public String getPropertyName() {
|
||||
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -82,8 +82,6 @@ public interface PropertyAccessor {
|
|||
* (may be a nested path and/or an indexed/mapped property)
|
||||
* @return the property type for the particular property,
|
||||
* or {@code null} if not determinable
|
||||
* @throws InvalidPropertyException if there is no such property or
|
||||
* if the property isn't readable
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
|
@ -97,8 +95,8 @@ public interface PropertyAccessor {
|
|||
* (may be a nested path and/or an indexed/mapped property)
|
||||
* @return the property type for the particular property,
|
||||
* or {@code null} if not determinable
|
||||
* @throws InvalidPropertyException if there is no such property or
|
||||
* if the property isn't readable
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
@Nullable
|
||||
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
|
||||
|
@ -113,6 +111,7 @@ public interface PropertyAccessor {
|
|||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
@Nullable
|
||||
Object getPropertyValue(String propertyName) throws BeansException;
|
||||
|
||||
/**
|
||||
|
@ -125,7 +124,7 @@ public interface PropertyAccessor {
|
|||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed or a type mismatch occurred
|
||||
*/
|
||||
void setPropertyValue(String propertyName, Object value) throws BeansException;
|
||||
void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||
|
||||
/**
|
||||
* Set the specified value as current property value.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Utility methods for classes that perform bean property access
|
||||
* according to the {@link PropertyAccessor} interface.
|
||||
|
@ -42,7 +44,7 @@ public abstract class PropertyAccessorUtils {
|
|||
* @param propertyPath the property path to check
|
||||
* @return whether the path indicates an indexed or nested property
|
||||
*/
|
||||
public static boolean isNestedOrIndexedProperty(String propertyPath) {
|
||||
public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath) {
|
||||
if (propertyPath == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -137,7 +139,7 @@ public abstract class PropertyAccessorUtils {
|
|||
* @param propertyName the bean property path
|
||||
* @return the canonical representation of the property path
|
||||
*/
|
||||
public static String canonicalPropertyName(String propertyName) {
|
||||
public static String canonicalPropertyName(@Nullable String propertyName) {
|
||||
if (propertyName == null) {
|
||||
return "";
|
||||
}
|
||||
|
@ -171,7 +173,8 @@ public abstract class PropertyAccessorUtils {
|
|||
* (as array of the same size)
|
||||
* @see #canonicalPropertyName(String)
|
||||
*/
|
||||
public static String[] canonicalPropertyNames(String[] propertyNames) {
|
||||
@Nullable
|
||||
public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) {
|
||||
if (propertyNames == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -48,7 +48,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
|||
* @param propertyAccessExceptions the List of PropertyAccessExceptions
|
||||
*/
|
||||
public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) {
|
||||
super(null);
|
||||
super(null, null);
|
||||
Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required");
|
||||
this.propertyAccessExceptions = propertyAccessExceptions;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Class<?> exType) {
|
||||
public boolean contains(@Nullable Class<?> exType) {
|
||||
if (exType == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
|
@ -60,7 +61,10 @@ class PropertyDescriptorUtils {
|
|||
/**
|
||||
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
|
||||
*/
|
||||
public static Class<?> findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException {
|
||||
@Nullable
|
||||
public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
|
||||
throws IntrospectionException {
|
||||
|
||||
Class<?> propertyType = null;
|
||||
|
||||
if (readMethod != null) {
|
||||
|
@ -103,8 +107,9 @@ class PropertyDescriptorUtils {
|
|||
/**
|
||||
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
|
||||
*/
|
||||
public static Class<?> findIndexedPropertyType(String name, Class<?> propertyType,
|
||||
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
||||
@Nullable
|
||||
public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
|
||||
@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {
|
||||
|
||||
Class<?> indexedPropertyType = null;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -112,7 +112,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
* Specify a Spring 3.0 ConversionService to use for converting
|
||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
*/
|
||||
public void setConversionService(ConversionService conversionService) {
|
||||
public void setConversionService(@Nullable ConversionService conversionService) {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
* @return the custom editor, or {@code null} if none specific for this property
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor getCustomEditor(String propertyName, Class<?> requiredType) {
|
||||
private PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
|
||||
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
|
||||
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
|
||||
}
|
||||
|
@ -391,7 +391,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
* @see java.beans.PropertyEditor#getAsText()
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor getCustomEditor(Class<?> requiredType) {
|
||||
private PropertyEditor getCustomEditor(@Nullable Class<?> requiredType) {
|
||||
if (requiredType == null || this.customEditors == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -521,7 +521,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
|
||||
private final Class<?> registeredType;
|
||||
|
||||
private CustomEditorHolder(PropertyEditor propertyEditor, Class<?> registeredType) {
|
||||
private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class<?> registeredType) {
|
||||
this.propertyEditor = propertyEditor;
|
||||
this.registeredType = registeredType;
|
||||
}
|
||||
|
@ -530,11 +530,12 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||
return this.propertyEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Class<?> getRegisteredType() {
|
||||
return this.registeredType;
|
||||
}
|
||||
|
||||
private PropertyEditor getPropertyEditor(Class<?> requiredType) {
|
||||
private PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) {
|
||||
// Special case: If no required type specified, which usually only happens for
|
||||
// Collection elements, or required type is not assignable to registered type,
|
||||
// which usually only happens for generic properties of type Object -
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.beans;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
|
@ -63,7 +64,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
|||
* @param name the name of the property (never {@code null})
|
||||
* @param value the value of the property (possibly before type conversion)
|
||||
*/
|
||||
public PropertyValue(String name, Object value) {
|
||||
public PropertyValue(String name, @Nullable Object value) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
@ -116,6 +118,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
|||
* It is the responsibility of the BeanWrapper implementation to
|
||||
* perform type conversion.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -37,7 +37,7 @@ public interface PropertyValues {
|
|||
/**
|
||||
* Return the property value with the given name, if any.
|
||||
* @param propertyName the name to search for
|
||||
* @return the property value, or {@code null}
|
||||
* @return the property value, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
PropertyValue getPropertyValue(String propertyName);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -50,7 +50,8 @@ public interface TypeConverter {
|
|||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
||||
|
||||
/**
|
||||
* Convert the value to the required type (if necessary from a String).
|
||||
|
@ -68,8 +69,9 @@ public interface TypeConverter {
|
|||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws TypeMismatchException;
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam) throws TypeMismatchException;
|
||||
|
||||
/**
|
||||
* Convert the value to the required type (if necessary from a String).
|
||||
|
@ -87,7 +89,8 @@ public interface TypeConverter {
|
|||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws TypeMismatchException;
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class TypeConverterDelegate {
|
|||
* @param propertyEditorRegistry the editor registry to use
|
||||
* @param targetObject the target object to work on (as context that can be passed to editors)
|
||||
*/
|
||||
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject) {
|
||||
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, @Nullable Object targetObject) {
|
||||
this.propertyEditorRegistry = propertyEditorRegistry;
|
||||
this.targetObject = targetObject;
|
||||
}
|
||||
|
@ -91,8 +91,9 @@ class TypeConverterDelegate {
|
|||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam) throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(null, null, newValue, requiredType,
|
||||
(methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
|
||||
|
@ -108,7 +109,8 @@ class TypeConverterDelegate {
|
|||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(null, null, newValue, requiredType,
|
||||
|
@ -125,9 +127,9 @@ class TypeConverterDelegate {
|
|||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(
|
||||
String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class<T> requiredType)
|
||||
throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||
Object newValue, @Nullable Class<T> requiredType) throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
|
||||
}
|
||||
|
@ -145,8 +147,9 @@ class TypeConverterDelegate {
|
|||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue,
|
||||
@Nullable Class<T> requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
|
||||
@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
||||
|
||||
// Custom editor for this type?
|
||||
PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);
|
||||
|
@ -268,7 +271,7 @@ class TypeConverterDelegate {
|
|||
// Original exception from former ConversionService call above...
|
||||
throw conversionAttemptEx;
|
||||
}
|
||||
else if (conversionService != null) {
|
||||
else if (conversionService != null && typeDescriptor != null) {
|
||||
// ConversionService not tried before, probably custom editor found
|
||||
// but editor couldn't produce the required type...
|
||||
TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
|
||||
|
@ -359,7 +362,7 @@ class TypeConverterDelegate {
|
|||
* @return the corresponding editor, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor findDefaultEditor(Class<?> requiredType) {
|
||||
private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {
|
||||
PropertyEditor editor = null;
|
||||
if (requiredType != null) {
|
||||
// No custom editor -> check BeanWrapperImpl's default editors.
|
||||
|
@ -383,7 +386,10 @@ class TypeConverterDelegate {
|
|||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
private Object doConvertValue(@Nullable Object oldValue, Object newValue, @Nullable Class<?> requiredType, PropertyEditor editor) {
|
||||
@Nullable
|
||||
private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
|
||||
@Nullable Class<?> requiredType, @Nullable PropertyEditor editor) {
|
||||
|
||||
Object convertedValue = newValue;
|
||||
|
||||
if (editor != null && !(convertedValue instanceof String)) {
|
||||
|
@ -459,7 +465,7 @@ class TypeConverterDelegate {
|
|||
return editor.getValue();
|
||||
}
|
||||
|
||||
private Object convertToTypedArray(Object input, String propertyName, Class<?> componentType) {
|
||||
private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {
|
||||
if (input instanceof Collection) {
|
||||
// Convert Collection elements to array elements.
|
||||
Collection<?> coll = (Collection<?>) input;
|
||||
|
@ -498,8 +504,8 @@ class TypeConverterDelegate {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<?> convertToTypedCollection(
|
||||
Collection<?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Collection<?> convertToTypedCollection(Collection<?> original, @Nullable String propertyName,
|
||||
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Collection.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
|
@ -515,7 +521,7 @@ class TypeConverterDelegate {
|
|||
}
|
||||
|
||||
boolean originalAllowed = requiredType.isInstance(original);
|
||||
TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
|
||||
TypeDescriptor elementType = (typeDescriptor != null ? typeDescriptor.getElementTypeDescriptor() : null);
|
||||
if (elementType == null && originalAllowed &&
|
||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||
return original;
|
||||
|
@ -524,13 +530,6 @@ class TypeConverterDelegate {
|
|||
Iterator<?> it;
|
||||
try {
|
||||
it = original.iterator();
|
||||
if (it == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Collection of type [" + original.getClass().getName() +
|
||||
"] returned null Iterator - injecting original Collection as-is");
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -580,8 +579,8 @@ class TypeConverterDelegate {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<?, ?> convertToTypedMap(
|
||||
Map<?, ?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Map<?, ?> convertToTypedMap(Map<?, ?> original, @Nullable String propertyName,
|
||||
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Map.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
|
@ -597,8 +596,8 @@ class TypeConverterDelegate {
|
|||
}
|
||||
|
||||
boolean originalAllowed = requiredType.isInstance(original);
|
||||
TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor();
|
||||
TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor();
|
||||
TypeDescriptor keyType = (typeDescriptor != null ? typeDescriptor.getMapKeyTypeDescriptor() : null);
|
||||
TypeDescriptor valueType = (typeDescriptor != null ? typeDescriptor.getMapValueTypeDescriptor() : null);
|
||||
if (keyType == null && valueType == null && originalAllowed &&
|
||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||
return original;
|
||||
|
@ -607,13 +606,6 @@ class TypeConverterDelegate {
|
|||
Iterator<?> it;
|
||||
try {
|
||||
it = original.entrySet().iterator();
|
||||
if (it == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Map of type [" + original.getClass().getName() +
|
||||
"] returned null Iterator - injecting original Map as-is");
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
@ -665,13 +657,15 @@ class TypeConverterDelegate {
|
|||
return (originalAllowed ? original : convertedCopy);
|
||||
}
|
||||
|
||||
private String buildIndexedPropertyName(String propertyName, int index) {
|
||||
@Nullable
|
||||
private String buildIndexedPropertyName(@Nullable String propertyName, int index) {
|
||||
return (propertyName != null ?
|
||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||
null);
|
||||
}
|
||||
|
||||
private String buildKeyedPropertyName(String propertyName, Object key) {
|
||||
@Nullable
|
||||
private String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
|
||||
return (propertyName != null ?
|
||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||
null);
|
||||
|
|
|
@ -37,26 +37,28 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
|||
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
||||
return doConvert(value, requiredType, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return doConvert(value, requiredType, methodParam, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return doConvert(value, requiredType, null, field);
|
||||
}
|
||||
|
||||
private <T> T doConvert(Object value, Class<T> requiredType, @Nullable MethodParameter methodParam, @Nullable Field field)
|
||||
throws TypeMismatchException {
|
||||
@Nullable
|
||||
private <T> T doConvert(@Nullable Object value,@Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam, @Nullable Field field) throws TypeMismatchException {
|
||||
|
||||
try {
|
||||
if (field != null) {
|
||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field);
|
||||
|
@ -65,16 +67,10 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
|||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
|
||||
}
|
||||
}
|
||||
catch (ConverterNotFoundException ex) {
|
||||
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConversionException | IllegalArgumentException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,9 @@ public class TypeMismatchException extends PropertyAccessException {
|
|||
* @param requiredType the required target type (or {@code null} if not known)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
|
||||
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType,
|
||||
@Nullable Throwable cause) {
|
||||
|
||||
super(propertyChangeEvent,
|
||||
"Failed to convert property value of type '" +
|
||||
ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -45,7 +45,7 @@ public abstract class AnnotationBeanUtils {
|
|||
* @param excludedProperties the names of excluded properties, if any
|
||||
* @see org.springframework.beans.BeanWrapper
|
||||
*/
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable String... excludedProperties) {
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, String... excludedProperties) {
|
||||
copyPropertiesToBean(ann, bean, null, excludedProperties);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,9 @@ public abstract class AnnotationBeanUtils {
|
|||
* @param excludedProperties the names of excluded properties, if any
|
||||
* @see org.springframework.beans.BeanWrapper
|
||||
*/
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, @Nullable String... excludedProperties) {
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver,
|
||||
String... excludedProperties) {
|
||||
|
||||
Set<String> excluded = new HashSet<>(Arrays.asList(excludedProperties));
|
||||
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
|
||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Callback that allows a bean to be aware of the bean
|
||||
* {@link ClassLoader class loader}; that is, the class loader used by the
|
||||
|
@ -47,11 +45,8 @@ public interface BeanClassLoaderAware extends Aware {
|
|||
* {@link InitializingBean InitializingBean's}
|
||||
* {@link InitializingBean#afterPropertiesSet()}
|
||||
* method or a custom init-method.
|
||||
* @param classLoader the owning class loader; may be {@code null} in
|
||||
* which case a default {@code ClassLoader} must be used, for example
|
||||
* the {@code ClassLoader} obtained via
|
||||
* {@link org.springframework.util.ClassUtils#getDefaultClassLoader()}
|
||||
* @param classLoader the owning class loader
|
||||
*/
|
||||
void setBeanClassLoader(@Nullable ClassLoader classLoader);
|
||||
void setBeanClassLoader(ClassLoader classLoader);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -64,7 +64,7 @@ public class BeanCreationException extends FatalBeanException {
|
|||
* @param msg the detail message
|
||||
*/
|
||||
public BeanCreationException(String beanName, String msg) {
|
||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") + ": " + msg);
|
||||
super("Error creating bean with name '" + beanName + "': " + msg);
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,8 @@ public class BeanCreationException extends FatalBeanException {
|
|||
* @param beanName the name of the bean requested
|
||||
* @param msg the detail message
|
||||
*/
|
||||
public BeanCreationException(String resourceDescription, String beanName, String msg) {
|
||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") +
|
||||
public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, String msg) {
|
||||
super("Error creating bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
|
@ -101,20 +101,12 @@ public class BeanCreationException extends FatalBeanException {
|
|||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeanCreationException(String resourceDescription, String beanName, String msg, Throwable cause) {
|
||||
public BeanCreationException(@Nullable String resourceDescription, String beanName, String msg, Throwable cause) {
|
||||
this(resourceDescription, beanName, msg);
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the bean requested, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the description of the resource that the bean
|
||||
* definition came from, if any.
|
||||
|
@ -124,6 +116,13 @@ public class BeanCreationException extends FatalBeanException {
|
|||
return this.resourceDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the bean requested, if any.
|
||||
*/
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a related cause to this bean creation exception,
|
||||
* not being a direct cause of the failure but having occurred
|
||||
|
@ -189,7 +188,7 @@ public class BeanCreationException extends FatalBeanException {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Class<?> exClass) {
|
||||
public boolean contains(@Nullable Class<?> exClass) {
|
||||
if (super.contains(exClass)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -57,7 +57,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
|||
* @param resourceDescription description of the resource that the bean definition came from
|
||||
* @param msg the detail message (used as exception message as-is)
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String msg) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) {
|
||||
super(msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
|||
* @param msg the detail message (used as exception message as-is)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
|||
* @param msg the detail message (appended to an introductory message that indicates
|
||||
* the resource and the name of the bean)
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg) {
|
||||
this(resourceDescription, beanName, msg, null);
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
|||
* the resource and the name of the bean)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -159,6 +159,22 @@ public interface BeanFactory {
|
|||
*/
|
||||
<T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
* overriding the specified default arguments (if any) in the bean definition.
|
||||
* @param name the name of the bean to retrieve
|
||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||
* the affected bean isn't a prototype
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @since 2.5
|
||||
*/
|
||||
Object getBean(String name, Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return the bean instance that uniquely matches the given object type, if any.
|
||||
* <p>This method goes into {@link ListableBeanFactory} by-type lookup territory
|
||||
|
@ -176,22 +192,6 @@ public interface BeanFactory {
|
|||
*/
|
||||
<T> T getBean(Class<T> requiredType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
* overriding the specified default arguments (if any) in the bean definition.
|
||||
* @param name the name of the bean to retrieve
|
||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||
* the affected bean isn't a prototype
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @since 2.5
|
||||
*/
|
||||
Object getBean(String name, Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
|
@ -298,7 +298,7 @@ public interface BeanFactory {
|
|||
* @see #getBean
|
||||
* @see #getType
|
||||
*/
|
||||
boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
||||
boolean isTypeMatch(String name, @Nullable Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
||||
|
||||
/**
|
||||
* Determine the type of the bean with the given name. More specifically,
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Map;
|
|||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
@ -57,7 +58,7 @@ public abstract class BeanFactoryUtils {
|
|||
* @return whether the given name is a factory dereference
|
||||
* @see BeanFactory#FACTORY_BEAN_PREFIX
|
||||
*/
|
||||
public static boolean isFactoryDereference(String name) {
|
||||
public static boolean isFactoryDereference(@Nullable String name) {
|
||||
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
|
||||
}
|
||||
|
||||
|
@ -86,7 +87,7 @@ public abstract class BeanFactoryUtils {
|
|||
* @see org.springframework.beans.factory.support.BeanDefinitionReaderUtils#generateBeanName
|
||||
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
||||
*/
|
||||
public static boolean isGeneratedBeanName(String name) {
|
||||
public static boolean isGeneratedBeanName(@Nullable String name) {
|
||||
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when the BeanFactory cannot load the specified class
|
||||
|
@ -44,10 +45,10 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
|||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) {
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
|
||||
|
||||
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName +
|
||||
"' defined in " + resourceDescription, cause);
|
||||
super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
this.beanClassName = beanClassName;
|
||||
|
@ -62,10 +63,11 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
|||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
String resourceDescription, String beanName, String beanClassName, LinkageError cause) {
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
|
||||
|
||||
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName +
|
||||
"' defined in " + resourceDescription + ": problem with class file or dependent class", cause);
|
||||
super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") +
|
||||
": problem with class file or dependent class", cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
this.beanClassName = beanClassName;
|
||||
|
|
|
@ -106,7 +106,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
|||
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
|
||||
* <p>Bean names returned by this method should always return bean names <i>in the
|
||||
* order of definition</i> in the backend configuration, as far as possible.
|
||||
* @param type the class or interface to match, or {@code null} for all bean names
|
||||
* @param type the generically typed class or interface to match
|
||||
* @return the names of beans (or objects created by FactoryBeans) matching
|
||||
* the given object type (including subclasses), or an empty array if none
|
||||
* @since 4.2
|
||||
|
@ -114,7 +114,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
|||
* @see FactoryBean#getObjectType
|
||||
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
|
||||
*/
|
||||
String[] getBeanNamesForType(@Nullable ResolvableType type);
|
||||
String[] getBeanNamesForType(ResolvableType type);
|
||||
|
||||
/**
|
||||
* Return the names of beans matching the given type (including subclasses),
|
||||
|
@ -268,7 +268,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
|||
* found on the given class itself.
|
||||
* @param beanName the name of the bean to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @return the annotation of the given type if found, or {@code null}
|
||||
* @return the annotation of the given type if found, or {@code null} otherwise
|
||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* @since 3.0
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Defines a factory which can return an Object instance
|
||||
|
@ -41,9 +42,10 @@ public interface ObjectFactory<T> {
|
|||
/**
|
||||
* Return an instance (possibly shared or independent)
|
||||
* of the object managed by this factory.
|
||||
* @return an instance of the bean (should never be {@code null})
|
||||
* @return the resulting instance
|
||||
* @throws BeansException in case of creation errors
|
||||
*/
|
||||
@Nullable
|
||||
T getObject() throws BeansException;
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public interface ObjectProvider<T> extends ObjectFactory<T> {
|
|||
* @throws BeansException in case of creation errors
|
||||
* @see #getObject()
|
||||
*/
|
||||
@Nullable
|
||||
T getObject(Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -228,10 +228,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||
if (beanType != null) {
|
||||
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -389,7 +387,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
}
|
||||
|
||||
|
||||
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
|
||||
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
|
||||
// Fall back to class name as cache key, for backwards compatibility with custom callers.
|
||||
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
|
||||
// Quick check on the concurrent map first, with minimal locking.
|
||||
|
@ -512,7 +510,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
/**
|
||||
* Register the specified bean as dependent on the autowired beans.
|
||||
*/
|
||||
private void registerDependentBeans(String beanName, Set<String> autowiredBeanNames) {
|
||||
private void registerDependentBeans(@Nullable String beanName, Set<String> autowiredBeanNames) {
|
||||
if (beanName != null) {
|
||||
for (String autowiredBeanName : autowiredBeanNames) {
|
||||
if (this.beanFactory.containsBean(autowiredBeanName)) {
|
||||
|
@ -529,7 +527,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
/**
|
||||
* Resolve the specified cached method argument or field value.
|
||||
*/
|
||||
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
|
||||
@Nullable
|
||||
private Object resolvedCachedArgument(@Nullable String beanName, Object cachedArgument) {
|
||||
if (cachedArgument instanceof DependencyDescriptor) {
|
||||
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
||||
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
|
||||
|
@ -557,7 +556,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
Field field = (Field) this.member;
|
||||
Object value;
|
||||
if (this.cached) {
|
||||
|
@ -615,13 +614,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
|
||||
private volatile Object[] cachedMethodArguments;
|
||||
|
||||
public AutowiredMethodElement(Method method, boolean required, PropertyDescriptor pd) {
|
||||
public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
|
||||
super(method, pd);
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
if (checkPropertySkipping(pvs)) {
|
||||
return;
|
||||
}
|
||||
|
@ -694,7 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private Object[] resolveCachedArguments(String beanName) {
|
||||
private Object[] resolveCachedArguments(@Nullable String beanName) {
|
||||
if (this.cachedMethodArguments == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
|||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -120,7 +121,9 @@ public abstract class BeanFactoryAnnotationUtils {
|
|||
* qualifier value (through {@code <qualifier>} or {@code @Qualifier})
|
||||
* @since 5.0
|
||||
*/
|
||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName, BeanFactory beanFactory) {
|
||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName,
|
||||
@Nullable BeanFactory beanFactory) {
|
||||
|
||||
// Try quick bean name or alias match first...
|
||||
if (qualifier.test(beanName)) {
|
||||
return true;
|
||||
|
|
|
@ -121,10 +121,8 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||
if (beanType != null) {
|
||||
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -77,7 +77,7 @@ public class InjectionMetadata {
|
|||
this.checkedElements = checkedElements;
|
||||
}
|
||||
|
||||
public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable {
|
||||
public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
Collection<InjectedElement> elementsToIterate =
|
||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||
if (!elementsToIterate.isEmpty()) {
|
||||
|
@ -94,7 +94,7 @@ public class InjectionMetadata {
|
|||
/**
|
||||
* @since 3.2.13
|
||||
*/
|
||||
public void clear(PropertyValues pvs) {
|
||||
public void clear(@Nullable PropertyValues pvs) {
|
||||
Collection<InjectedElement> elementsToIterate =
|
||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||
if (!elementsToIterate.isEmpty()) {
|
||||
|
@ -105,7 +105,7 @@ public class InjectionMetadata {
|
|||
}
|
||||
|
||||
|
||||
public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz) {
|
||||
public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class<?> clazz) {
|
||||
return (metadata == null || metadata.targetClass != clazz);
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class InjectionMetadata {
|
|||
|
||||
protected volatile Boolean skip;
|
||||
|
||||
protected InjectedElement(Member member, PropertyDescriptor pd) {
|
||||
protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
|
||||
this.member = member;
|
||||
this.isField = (member instanceof Field);
|
||||
this.pd = pd;
|
||||
|
@ -163,7 +163,9 @@ public class InjectionMetadata {
|
|||
/**
|
||||
* Either this or {@link #getResourceToInject} needs to be overridden.
|
||||
*/
|
||||
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object target, @Nullable String requestingBeanName, @Nullable PropertyValues pvs)
|
||||
throws Throwable {
|
||||
|
||||
if (this.isField) {
|
||||
Field field = (Field) this.member;
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
@ -189,7 +191,7 @@ public class InjectionMetadata {
|
|||
* an explicit property value having been specified. Also marks the
|
||||
* affected property as processed for other processors to ignore it.
|
||||
*/
|
||||
protected boolean checkPropertySkipping(PropertyValues pvs) {
|
||||
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
|
||||
if (this.skip != null) {
|
||||
return this.skip;
|
||||
}
|
||||
|
@ -219,7 +221,7 @@ public class InjectionMetadata {
|
|||
/**
|
||||
* @since 3.2.13
|
||||
*/
|
||||
protected void clearPropertySkipping(PropertyValues pvs) {
|
||||
protected void clearPropertySkipping(@Nullable PropertyValues pvs) {
|
||||
if (pvs == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -234,7 +236,7 @@ public class InjectionMetadata {
|
|||
* Either this or {@link #inject} needs to be overridden.
|
||||
*/
|
||||
@Nullable
|
||||
protected Object getResourceToInject(Object target, String requestingBeanName) {
|
||||
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
|||
@Override
|
||||
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
|
||||
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
|
||||
if (match && descriptor != null) {
|
||||
if (match) {
|
||||
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
|
||||
if (match) {
|
||||
MethodParameter methodParam = descriptor.getMethodParameter();
|
||||
|
@ -298,11 +298,13 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
|||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
|
||||
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
|
||||
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -39,6 +39,7 @@ import org.springframework.core.Conventions;
|
|||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -170,7 +171,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
|
|||
* @param beanName the name of the bean to check against
|
||||
* @return {@code true} to skip the bean; {@code false} to process it
|
||||
*/
|
||||
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
protected boolean shouldSkip(@Nullable ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public abstract class AbstractFactoryBean<T>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -268,6 +268,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
|||
* @return the bean instance to use, either the original or a wrapped one
|
||||
* @throws BeansException if the initialization failed
|
||||
*/
|
||||
@Nullable
|
||||
Object initializeBean(Object existingBean, String beanName) throws BeansException;
|
||||
|
||||
/**
|
||||
|
@ -280,6 +281,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
|||
* @throws BeansException if any post-processing failed
|
||||
* @see BeanPostProcessor#postProcessBeforeInitialization
|
||||
*/
|
||||
@Nullable
|
||||
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
|
||||
throws BeansException;
|
||||
|
||||
|
@ -293,6 +295,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
|||
* @throws BeansException if any post-processing failed
|
||||
* @see BeanPostProcessor#postProcessAfterInitialization
|
||||
*/
|
||||
@Nullable
|
||||
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
|
||||
throws BeansException;
|
||||
|
||||
|
@ -356,7 +359,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
|||
* @see DependencyDescriptor
|
||||
*/
|
||||
@Nullable
|
||||
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
|
||||
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
|
||||
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -101,7 +101,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
* @see #setFactoryBeanName
|
||||
* @see #setFactoryMethodName
|
||||
*/
|
||||
void setBeanClassName(String beanClassName);
|
||||
void setBeanClassName(@Nullable String beanClassName);
|
||||
|
||||
/**
|
||||
* Return the current bean class name of this bean definition.
|
||||
|
@ -115,6 +115,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
* @see #getFactoryBeanName()
|
||||
* @see #getFactoryMethodName()
|
||||
*/
|
||||
@Nullable
|
||||
String getBeanClassName();
|
||||
|
||||
/**
|
||||
|
@ -122,11 +123,10 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
* @see #SCOPE_SINGLETON
|
||||
* @see #SCOPE_PROTOTYPE
|
||||
*/
|
||||
void setScope(String scope);
|
||||
void setScope(@Nullable String scope);
|
||||
|
||||
/**
|
||||
* Return the name of the current target scope for this bean,
|
||||
* or {@code null} if not known yet.
|
||||
* Return the name of the current target scope for this bean.
|
||||
*/
|
||||
@Nullable
|
||||
String getScope();
|
||||
|
@ -153,6 +153,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
/**
|
||||
* Return the bean names that this bean depends on.
|
||||
*/
|
||||
@Nullable
|
||||
String[] getDependsOn();
|
||||
|
||||
/**
|
||||
|
@ -186,7 +187,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
* This the name of the bean to call the specified factory method on.
|
||||
* @see #setFactoryMethodName
|
||||
*/
|
||||
void setFactoryBeanName(String factoryBeanName);
|
||||
void setFactoryBeanName(@Nullable String factoryBeanName);
|
||||
|
||||
/**
|
||||
* Return the factory bean name, if any.
|
||||
|
@ -202,7 +203,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
* @see #setFactoryBeanName
|
||||
* @see #setBeanClassName
|
||||
*/
|
||||
void setFactoryMethodName(String factoryMethodName);
|
||||
void setFactoryMethodName(@Nullable String factoryMethodName);
|
||||
|
||||
/**
|
||||
* Return a factory method, if any.
|
||||
|
@ -259,6 +260,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
|||
/**
|
||||
* Return a human-readable description of this bean definition.
|
||||
*/
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -120,7 +120,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
|
|||
* Determine whether the given candidate name matches the bean name
|
||||
* or the aliases stored in this bean definition.
|
||||
*/
|
||||
public boolean matchesName(String candidateName) {
|
||||
public boolean matchesName(@Nullable String candidateName) {
|
||||
return (candidateName != null && (candidateName.equals(this.beanName) ||
|
||||
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
|
||||
ObjectUtils.containsElement(this.aliases, candidateName)));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -24,6 +24,7 @@ import java.util.Set;
|
|||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
@ -164,7 +165,8 @@ public class BeanDefinitionVisitor {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object resolveValue(Object value) {
|
||||
@Nullable
|
||||
protected Object resolveValue(@Nullable Object value) {
|
||||
if (value instanceof BeanDefinition) {
|
||||
visitBeanDefinition((BeanDefinition) value);
|
||||
}
|
||||
|
@ -174,6 +176,9 @@ public class BeanDefinitionVisitor {
|
|||
else if (value instanceof RuntimeBeanReference) {
|
||||
RuntimeBeanReference ref = (RuntimeBeanReference) value;
|
||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||
if (newBeanName == null) {
|
||||
return null;
|
||||
}
|
||||
if (!newBeanName.equals(ref.getBeanName())) {
|
||||
return new RuntimeBeanReference(newBeanName);
|
||||
}
|
||||
|
@ -181,6 +186,9 @@ public class BeanDefinitionVisitor {
|
|||
else if (value instanceof RuntimeBeanNameReference) {
|
||||
RuntimeBeanNameReference ref = (RuntimeBeanNameReference) value;
|
||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||
if (newBeanName == null) {
|
||||
return null;
|
||||
}
|
||||
if (!newBeanName.equals(ref.getBeanName())) {
|
||||
return new RuntimeBeanNameReference(newBeanName);
|
||||
}
|
||||
|
@ -274,6 +282,7 @@ public class BeanDefinitionVisitor {
|
|||
* @param strVal the original String value
|
||||
* @return the resolved String value
|
||||
*/
|
||||
@Nullable
|
||||
protected String resolveStringValue(String strVal) {
|
||||
if (this.valueResolver == null) {
|
||||
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.beans.factory.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for resolving a value through evaluating it
|
||||
|
@ -40,6 +41,7 @@ public interface BeanExpressionResolver {
|
|||
* @return the resolved value (potentially the given value as-is)
|
||||
* @throws BeansException if evaluation failed
|
||||
*/
|
||||
Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException;
|
||||
@Nullable
|
||||
Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -134,12 +134,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
|||
* here, supporting "#{...}" expressions in a Unified EL compatible style.
|
||||
* @since 3.0
|
||||
*/
|
||||
void setBeanExpressionResolver(BeanExpressionResolver resolver);
|
||||
void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver);
|
||||
|
||||
/**
|
||||
* Return the resolution strategy for expressions in bean definition values.
|
||||
* @since 3.0
|
||||
*/
|
||||
@Nullable
|
||||
BeanExpressionResolver getBeanExpressionResolver();
|
||||
|
||||
/**
|
||||
|
@ -147,7 +148,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
|||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
* @since 3.0
|
||||
*/
|
||||
void setConversionService(ConversionService conversionService);
|
||||
void setConversionService(@Nullable ConversionService conversionService);
|
||||
|
||||
/**
|
||||
* Return the associated ConversionService, if any.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -78,7 +78,7 @@ public interface ConfigurableListableBeanFactory
|
|||
* implementation of the {@link org.springframework.beans.factory.ObjectFactory}
|
||||
* interface, which allows for lazy resolution of the actual target value.
|
||||
*/
|
||||
void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);
|
||||
void registerResolvableDependency(Class<?> dependencyType, @Nullable Object autowiredValue);
|
||||
|
||||
/**
|
||||
* Determine whether the specified bean qualifies as an autowire candidate,
|
||||
|
@ -106,7 +106,7 @@ public interface ConfigurableListableBeanFactory
|
|||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* defined in this factory
|
||||
*/
|
||||
BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException;
|
||||
BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
|
||||
|
||||
/**
|
||||
* Return a unified view over all bean names managed by this factory.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -70,7 +70,7 @@ public class ConstructorArgumentValues {
|
|||
* to allow for merging and re-merging of argument value definitions. Distinct
|
||||
* ValueHolder instances carrying the same content are of course allowed.
|
||||
*/
|
||||
public void addArgumentValues(ConstructorArgumentValues other) {
|
||||
public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
|
||||
if (other != null) {
|
||||
for (Map.Entry<Integer, ValueHolder> entry : other.indexedArgumentValues.entrySet()) {
|
||||
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
|
||||
|
@ -89,7 +89,7 @@ public class ConstructorArgumentValues {
|
|||
* @param index the index in the constructor argument list
|
||||
* @param value the argument value
|
||||
*/
|
||||
public void addIndexedArgumentValue(int index, Object value) {
|
||||
public void addIndexedArgumentValue(int index, @Nullable Object value) {
|
||||
addIndexedArgumentValue(index, new ValueHolder(value));
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class ConstructorArgumentValues {
|
|||
* @param value the argument value
|
||||
* @param type the type of the constructor argument
|
||||
*/
|
||||
public void addIndexedArgumentValue(int index, Object value, String type) {
|
||||
public void addIndexedArgumentValue(int index, @Nullable Object value, String type) {
|
||||
addIndexedArgumentValue(index, new ValueHolder(value, type));
|
||||
}
|
||||
|
||||
|
@ -453,7 +453,7 @@ public class ConstructorArgumentValues {
|
|||
* Create a new ValueHolder for the given value.
|
||||
* @param value the argument value
|
||||
*/
|
||||
public ValueHolder(Object value) {
|
||||
public ValueHolder(@Nullable Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -462,7 +462,7 @@ public class ConstructorArgumentValues {
|
|||
* @param value the argument value
|
||||
* @param type the type of the constructor argument
|
||||
*/
|
||||
public ValueHolder(Object value, String type) {
|
||||
public ValueHolder(@Nullable Object value, @Nullable String type) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -473,7 +473,7 @@ public class ConstructorArgumentValues {
|
|||
* @param type the type of the constructor argument
|
||||
* @param name the name of the constructor argument
|
||||
*/
|
||||
public ValueHolder(Object value, String type, String name) {
|
||||
public ValueHolder(@Nullable Object value, @Nullable String type, @Nullable String name) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
|
@ -483,13 +483,14 @@ public class ConstructorArgumentValues {
|
|||
* Set the value for the constructor argument.
|
||||
* @see PropertyPlaceholderConfigurer
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
public void setValue(@Nullable Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
@ -497,13 +498,14 @@ public class ConstructorArgumentValues {
|
|||
/**
|
||||
* Set the type of the constructor argument.
|
||||
*/
|
||||
public void setType(String type) {
|
||||
public void setType(@Nullable String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
@ -511,13 +513,14 @@ public class ConstructorArgumentValues {
|
|||
/**
|
||||
* Set the name of the constructor argument.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
@ -526,11 +529,12 @@ public class ConstructorArgumentValues {
|
|||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
|
|
@ -99,12 +99,9 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
|||
|
||||
this.declaringClass = methodParameter.getDeclaringClass();
|
||||
if (this.methodParameter.getMethod() != null) {
|
||||
this.methodName = methodParameter.getMethod().getName();
|
||||
this.parameterTypes = methodParameter.getMethod().getParameterTypes();
|
||||
}
|
||||
else {
|
||||
this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
|
||||
this.methodName = this.methodParameter.getMethod().getName();
|
||||
}
|
||||
this.parameterTypes = methodParameter.getExecutable().getParameterTypes();
|
||||
this.parameterIndex = methodParameter.getParameterIndex();
|
||||
this.containingClass = methodParameter.getContainingClass();
|
||||
this.required = required;
|
||||
|
@ -334,6 +331,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
|||
* Determine the name of the wrapped parameter/field.
|
||||
* @return the declared name (never {@code null})
|
||||
*/
|
||||
@Nullable
|
||||
public String getDependencyName() {
|
||||
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -44,7 +44,6 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
|||
* <p>This can be specified to not log into the category of this warner class but rather
|
||||
* into a specific named category.
|
||||
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
||||
* @see org.apache.log4j.Logger#getLogger(String)
|
||||
* @see java.util.logging.Logger#getLogger(String)
|
||||
*/
|
||||
public void setLoggerName(String loggerName) {
|
||||
|
@ -61,10 +60,13 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
|||
if (beanFactory.isFactoryBean(beanName)) {
|
||||
nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
|
||||
}
|
||||
Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
|
||||
if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||
logDeprecatedBean(beanName, beanType, beanDefinition);
|
||||
Class<?> beanType = beanFactory.getType(nameToLookup);
|
||||
if (beanType != null) {
|
||||
Class<?> userClass = ClassUtils.getUserClass(beanType);
|
||||
if (userClass.isAnnotationPresent(Deprecated.class)) {
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||
logDeprecatedBean(beanName, beanType, beanDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue