@Nullable all the way: null-safety at field level

This commits extends nullability declarations to the field level, formalizing the interaction between methods and their underlying fields and therefore avoiding any nullability mismatch.

Issue: SPR-15720
This commit is contained in:
Juergen Hoeller
2017-06-30 01:53:45 +02:00
parent c4694c3f5c
commit cc74a2891a
936 changed files with 6090 additions and 2806 deletions

View File

@@ -104,11 +104,11 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
private final AspectInstanceFactory aspectInstanceFactory;
/**
* The name of the aspect (ref bean) in which this advice was defined (used
* when determining advice precedence so that we can determine
* The name of the aspect (ref bean) in which this advice was defined
* (used when determining advice precedence so that we can determine
* whether two pieces of advice come from the same aspect).
*/
private String aspectName;
private String aspectName = "";
/**
* The order of declaration of this advice within the aspect.
@@ -119,13 +119,16 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* This will be non-null if the creator of this advice object knows the argument names
* and sets them explicitly
*/
private String[] argumentNames = null;
@Nullable
private String[] argumentNames;
/** Non-null if after throwing advice binds the thrown value */
private String throwingName = null;
@Nullable
private String throwingName;
/** Non-null if after returning advice binds the return value */
private String returningName = null;
@Nullable
private String returningName;
private Class<?> discoveredReturningType = Object.class;
@@ -143,10 +146,12 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
*/
private int joinPointStaticPartArgumentIndex = -1;
@Nullable
private Map<String, Integer> argumentBindings;
private boolean argumentsIntrospected = false;
@Nullable
private Type discoveredReturningGenericType;
// Note: Unlike return type, no such generic information is needed for the throwing type,
// since Java doesn't allow exception types to be parameterized.
@@ -464,6 +469,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
private void bindExplicitArguments(int numArgumentsLeftToBind) {
Assert.state(this.argumentNames != null, "No argument names available");
this.argumentBindings = new HashMap<>();
int numExpectedArgumentNames = this.aspectJAdviceMethod.getParameterCount();
@@ -504,7 +510,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
// configure the pointcut expression accordingly.
configurePointcutParameters(argumentIndexOffset);
configurePointcutParameters(this.argumentNames, argumentIndexOffset);
}
/**
@@ -512,7 +518,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* pointcut parameters - but returning and throwing vars are handled differently
* and must be removed from the list if present.
*/
private void configurePointcutParameters(int argumentIndexOffset) {
private void configurePointcutParameters(String[] argumentNames, int argumentIndexOffset) {
int numParametersToRemove = argumentIndexOffset;
if (this.returningName != null) {
numParametersToRemove++;
@@ -520,20 +526,20 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
if (this.throwingName != null) {
numParametersToRemove++;
}
String[] pointcutParameterNames = new String[this.argumentNames.length - numParametersToRemove];
String[] pointcutParameterNames = new String[argumentNames.length - numParametersToRemove];
Class<?>[] pointcutParameterTypes = new Class<?>[pointcutParameterNames.length];
Class<?>[] methodParameterTypes = this.aspectJAdviceMethod.getParameterTypes();
int index = 0;
for (int i = 0; i < this.argumentNames.length; i++) {
for (int i = 0; i < argumentNames.length; i++) {
if (i < argumentIndexOffset) {
continue;
}
if (this.argumentNames[i].equals(this.returningName) ||
this.argumentNames[i].equals(this.throwingName)) {
if (argumentNames[i].equals(this.returningName) ||
argumentNames[i].equals(this.throwingName)) {
continue;
}
pointcutParameterNames[index] = this.argumentNames[i];
pointcutParameterNames[index] = argumentNames[i];
pointcutParameterTypes[index] = methodParameterTypes[i];
index++;
}

View File

@@ -114,6 +114,7 @@ import org.springframework.util.StringUtils;
* returning {@code null} in the case that the parameter names cannot be discovered.
*
* @author Adrian Colyer
* @author Juergen Hoeller
* @since 2.0
*/
public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {
@@ -155,26 +156,23 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
}
private boolean raiseExceptions;
/**
* If the advice is afterReturning, and binds the return value, this is the parameter name used.
*/
private String returningName;
/**
* If the advice is afterThrowing, and binds the thrown value, this is the parameter name used.
*/
private String throwingName;
/**
* The pointcut expression associated with the advice, as a simple String.
*/
/** The pointcut expression associated with the advice, as a simple String */
@Nullable
private String pointcutExpression;
private Class<?>[] argumentTypes;
private boolean raiseExceptions;
private String[] parameterNameBindings;
/** If the advice is afterReturning, and binds the return value, this is the parameter name used */
@Nullable
private String returningName;
/** If the advice is afterThrowing, and binds the thrown value, this is the parameter name used */
@Nullable
private String throwingName;
private Class<?>[] argumentTypes = new Class<?>[0];
private String[] parameterNameBindings = new String[0];
private int numberOfRemainingUnboundArguments;
@@ -202,7 +200,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* returning variable name must be specified.
* @param returningName the name of the returning variable
*/
public void setReturningName(String returningName) {
public void setReturningName(@Nullable String returningName) {
this.returningName = returningName;
}
@@ -211,7 +209,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* throwing variable name must be specified.
* @param throwingName the name of the throwing variable
*/
public void setThrowingName(String throwingName) {
public void setThrowingName(@Nullable String throwingName) {
this.throwingName = throwingName;
}
@@ -781,6 +779,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
private int numTokensConsumed;
@Nullable
private String text;
public PointcutBody(int tokens, @Nullable String text) {

View File

@@ -102,16 +102,20 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
private static final Log logger = LogFactory.getLog(AspectJExpressionPointcut.class);
@Nullable
private Class<?> pointcutDeclarationScope;
private String[] pointcutParameterNames = new String[0];
private Class<?>[] pointcutParameterTypes = new Class<?>[0];
@Nullable
private BeanFactory beanFactory;
@Nullable
private transient ClassLoader pointcutClassLoader;
@Nullable
private transient PointcutExpression pointcutExpression;
private transient Map<Method, ShadowMatch> shadowMatchCache = new ConcurrentHashMap<>(32);
@@ -169,13 +173,13 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@Override
public ClassFilter getClassFilter() {
checkReadyToMatch();
obtainPointcutExpression();
return this;
}
@Override
public MethodMatcher getMethodMatcher() {
checkReadyToMatch();
obtainPointcutExpression();
return this;
}
@@ -184,7 +188,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* Check whether this pointcut is ready to match,
* lazily building the underlying AspectJ pointcut expression.
*/
private void checkReadyToMatch() {
private PointcutExpression obtainPointcutExpression() {
if (getExpression() == null) {
throw new IllegalStateException("Must set property 'expression' before attempting to match");
}
@@ -192,6 +196,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
this.pointcutClassLoader = determinePointcutClassLoader();
this.pointcutExpression = buildPointcutExpression(this.pointcutClassLoader);
}
return this.pointcutExpression;
}
/**
@@ -258,16 +263,15 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* Return the underlying AspectJ pointcut expression.
*/
public PointcutExpression getPointcutExpression() {
checkReadyToMatch();
return this.pointcutExpression;
return obtainPointcutExpression();
}
@Override
public boolean matches(Class<?> targetClass) {
checkReadyToMatch();
PointcutExpression pointcutExpression = obtainPointcutExpression();
try {
try {
return this.pointcutExpression.couldMatchJoinPointsInType(targetClass);
return pointcutExpression.couldMatchJoinPointsInType(targetClass);
}
catch (ReflectionWorldException ex) {
logger.debug("PointcutExpression matching rejected target class - trying fallback expression", ex);
@@ -286,7 +290,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@Override
public boolean matches(Method method, @Nullable Class<?> targetClass, boolean beanHasIntroductions) {
checkReadyToMatch();
obtainPointcutExpression();
Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
ShadowMatch shadowMatch = getShadowMatch(targetMethod, method);
@@ -321,13 +325,12 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@Override
public boolean isRuntime() {
checkReadyToMatch();
return this.pointcutExpression.mayNeedDynamicTest();
return obtainPointcutExpression().mayNeedDynamicTest();
}
@Override
public boolean matches(Method method, @Nullable Class<?> targetClass, Object... args) {
checkReadyToMatch();
obtainPointcutExpression();
ShadowMatch shadowMatch = getShadowMatch(AopUtils.getMostSpecificMethod(method, targetClass), method);
ShadowMatch originalShadowMatch = getShadowMatch(method, method);
@@ -436,7 +439,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
if (shadowMatch == null) {
try {
try {
shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch);
}
catch (ReflectionWorldException ex) {
// Failed to introspect target method, probably because it has been loaded
@@ -454,7 +457,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
if (shadowMatch == null && targetMethod != originalMethod) {
methodToMatch = originalMethod;
try {
shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch);
}
catch (ReflectionWorldException ex3) {
// Could neither introspect the target class nor the proxy class ->
@@ -519,18 +522,16 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("AspectJExpressionPointcut: ");
if (this.pointcutParameterNames != null && this.pointcutParameterTypes != null) {
sb.append("(");
for (int i = 0; i < this.pointcutParameterTypes.length; i++) {
sb.append(this.pointcutParameterTypes[i].getName());
sb.append(" ");
sb.append(this.pointcutParameterNames[i]);
if ((i+1) < this.pointcutParameterTypes.length) {
sb.append(", ");
}
sb.append("(");
for (int i = 0; i < this.pointcutParameterTypes.length; i++) {
sb.append(this.pointcutParameterTypes[i].getName());
sb.append(" ");
sb.append(this.pointcutParameterNames[i]);
if ((i+1) < this.pointcutParameterTypes.length) {
sb.append(", ");
}
sb.append(")");
}
sb.append(")");
sb.append(" ");
if (getExpression() != null) {
sb.append(getExpression());

View File

@@ -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 org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -38,6 +39,7 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered {
private final Pointcut pointcut;
@Nullable
private Integer order;

View File

@@ -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.
@@ -57,12 +57,15 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
private final ProxyMethodInvocation methodInvocation;
@Nullable
private Object[] defensiveCopyOfArgs;
/** Lazily initialized signature object */
@Nullable
private Signature signature;
/** Lazily initialized source location object */
@Nullable
private SourceLocation sourceLocation;
@@ -178,6 +181,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
*/
private class MethodSignatureImpl implements MethodSignature {
@Nullable
private volatile String[] parameterNames;
@Override
@@ -216,6 +220,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
}
@Override
@Nullable
public String[] getParameterNames() {
if (this.parameterNames == null) {
this.parameterNames = parameterNameDiscoverer.getParameterNames(getMethod());

View File

@@ -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.
@@ -37,6 +37,7 @@ import org.aspectj.weaver.reflect.ReflectionVar;
import org.aspectj.weaver.reflect.ShadowMatchImpl;
import org.aspectj.weaver.tools.ShadowMatch;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -78,6 +79,7 @@ class RuntimeTestWalker {
}
@Nullable
private final Test runtimeTest;

View File

@@ -20,6 +20,7 @@ import org.aspectj.weaver.tools.PointcutParser;
import org.aspectj.weaver.tools.TypePatternMatcher;
import org.springframework.aop.ClassFilter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -32,8 +33,9 @@ import org.springframework.util.StringUtils;
*/
public class TypePatternClassFilter implements ClassFilter {
private String typePattern;
private String typePattern = "";
@Nullable
private TypePatternMatcher aspectJTypePatternMatcher;
@@ -51,8 +53,6 @@ public class TypePatternClassFilter implements ClassFilter {
* Create a fully configured {@link TypePatternClassFilter} using the
* given type pattern.
* @param typePattern the type pattern that AspectJ weaver should parse
* @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null}
* or is recognized as invalid
*/
public TypePatternClassFilter(String typePattern) {
setTypePattern(typePattern);
@@ -73,8 +73,6 @@ public class TypePatternClassFilter implements ClassFilter {
* that implements it.
* <p>These conventions are established by AspectJ, not Spring AOP.
* @param typePattern the type pattern that AspectJ weaver should parse
* @throws IllegalArgumentException if the supplied {@code typePattern} is {@code null}
* or is recognized as invalid
*/
public void setTypePattern(String typePattern) {
Assert.notNull(typePattern, "Type pattern must not be null");

View File

@@ -212,9 +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) {
Method method;
try {
@@ -226,11 +224,11 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
if (method != null) {
String candidate = (String) method.invoke(annotation);
if (StringUtils.hasText(candidate)) {
expression = candidate;
return candidate;
}
}
}
return expression;
throw new IllegalStateException("Failed to resolve expression: " + annotation);
}
public AspectJAnnotationType getAnnotationType() {

View File

@@ -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.
@@ -24,6 +24,7 @@ import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -48,10 +49,13 @@ import org.springframework.util.Assert;
@SuppressWarnings("serial")
public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorAutoProxyCreator {
@Nullable
private List<Pattern> includePatterns;
@Nullable
private AspectJAdvisorFactory aspectJAdvisorFactory;
@Nullable
private BeanFactoryAspectJAdvisorsBuilder aspectJAdvisorsBuilder;
@@ -87,7 +91,9 @@ public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorA
// Add all the Spring advisors found according to superclass rules.
List<Advisor> advisors = super.findCandidateAdvisors();
// Build Advisors for all AspectJ aspects in the bean factory.
advisors.addAll(this.aspectJAdvisorsBuilder.buildAspectJAdvisors());
if (this.aspectJAdvisorsBuilder != null) {
advisors.addAll(this.aspectJAdvisorsBuilder.buildAspectJAdvisors());
}
return advisors;
}
@@ -101,7 +107,8 @@ public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorA
// proxied by that interface and fail at runtime as the advice method is not
// defined on the interface. We could potentially relax the restriction about
// not advising aspects in the future.
return (super.isInfrastructureClass(beanClass) || this.aspectJAdvisorFactory.isAspect(beanClass));
return (super.isInfrastructureClass(beanClass) ||
(this.aspectJAdvisorFactory != null && this.aspectJAdvisorFactory.isAspect(beanClass)));
}
/**

View File

@@ -104,19 +104,19 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
@Override
public Object getAspectCreationMutex() {
if (this.beanFactory != null) {
if (this.beanFactory.isSingleton(name)) {
// Rely on singleton semantics provided by the factory -> no local lock.
return null;
}
else if (this.beanFactory instanceof ConfigurableBeanFactory) {
// No singleton guarantees from the factory -> let's lock locally but
// reuse the factory's singleton lock, just in case a lazy dependency
// of our advice bean happens to trigger the singleton lock implicitly...
return ((ConfigurableBeanFactory) this.beanFactory).getSingletonMutex();
}
if (this.beanFactory.isSingleton(this.name)) {
// Rely on singleton semantics provided by the factory -> no local lock.
return null;
}
else if (this.beanFactory instanceof ConfigurableBeanFactory) {
// No singleton guarantees from the factory -> let's lock locally but
// reuse the factory's singleton lock, just in case a lazy dependency
// of our advice bean happens to trigger the singleton lock implicitly...
return ((ConfigurableBeanFactory) this.beanFactory).getSingletonMutex();
}
else {
return this;
}
return this;
}
/**

View File

@@ -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.aspectj.lang.reflect.PerClauseKind;
import org.springframework.aop.Advisor;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -43,6 +44,7 @@ public class BeanFactoryAspectJAdvisorsBuilder {
private final AspectJAdvisorFactory advisorFactory;
@Nullable
private volatile List<String> aspectBeanNames;
private final Map<String, List<Advisor>> advisorsCache = new ConcurrentHashMap<>();

View File

@@ -70,10 +70,13 @@ class InstantiationModelAwarePointcutAdvisorImpl
private final boolean lazy;
@Nullable
private Advice instantiatedAdvice;
@Nullable
private Boolean isBeforeAdvice;
@Nullable
private Boolean isAfterAdvice;
@@ -267,10 +270,12 @@ class InstantiationModelAwarePointcutAdvisorImpl
private final Pointcut preInstantiationPointcut;
@Nullable
private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory;
private PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut,
Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) {
this.declaredPointcut = declaredPointcut;
this.preInstantiationPointcut = preInstantiationPointcut;
if (aspectInstanceFactory instanceof LazySingletonAspectInstanceFactoryDecorator) {

View File

@@ -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.aop.aspectj.annotation;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -32,6 +33,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
private final MetadataAwareAspectInstanceFactory maaif;
@Nullable
private volatile Object materialized;
@@ -47,20 +49,24 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar
@Override
public Object getAspectInstance() {
if (this.materialized == null) {
Object aspectInstance = this.materialized;
if (aspectInstance == null) {
Object mutex = this.maaif.getAspectCreationMutex();
if (mutex == null) {
this.materialized = this.maaif.getAspectInstance();
aspectInstance = this.maaif.getAspectInstance();
this.materialized = aspectInstance;
}
else {
synchronized (mutex) {
if (this.materialized == null) {
this.materialized = this.maaif.getAspectInstance();
aspectInstance = this.materialized;
if (aspectInstance == null) {
aspectInstance = this.maaif.getAspectInstance();
this.materialized = aspectInstance;
}
}
}
}
return this.materialized;
return aspectInstance;
}
public boolean isMaterialized() {

View File

@@ -86,6 +86,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
}
@Nullable
private final BeanFactory beanFactory;
@@ -209,7 +210,9 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
AspectJExpressionPointcut ajexp =
new AspectJExpressionPointcut(candidateAspectClass, new String[0], new Class<?>[0]);
ajexp.setExpression(aspectJAnnotation.getPointcutExpression());
ajexp.setBeanFactory(this.beanFactory);
if (this.beanFactory != null) {
ajexp.setBeanFactory(this.beanFactory);
}
return ajexp;
}

View File

@@ -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.
@@ -22,6 +22,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -32,10 +33,13 @@ import org.springframework.util.StringUtils;
*/
public class MethodLocatingFactoryBean implements FactoryBean<Method>, BeanFactoryAware {
@Nullable
private String targetBeanName;
@Nullable
private String methodName;
@Nullable
private Method method;

View File

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -41,19 +42,25 @@ import org.springframework.util.ClassUtils;
public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
implements FactoryBean<Object>, BeanClassLoaderAware, InitializingBean {
@Nullable
private Object target;
@Nullable
private Class<?>[] proxyInterfaces;
@Nullable
private Object[] preInterceptors;
@Nullable
private Object[] postInterceptors;
/** Default is global AdvisorAdapterRegistry */
private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
@Nullable
private transient ClassLoader proxyClassLoader;
@Nullable
private Object proxy;

View File

@@ -220,8 +220,11 @@ public abstract class AopProxyUtils {
* @return a cloned argument array, or the original if no adaptation is needed
* @since 4.2.3
*/
static Object[] adaptArgumentsIfNecessary(Method method, Object... arguments) {
if (method.isVarArgs() && !ObjectUtils.isEmpty(arguments)) {
static Object[] adaptArgumentsIfNecessary(Method method, @Nullable Object[] arguments) {
if (ObjectUtils.isEmpty(arguments)) {
return new Object[0];
}
if (method.isVarArgs()) {
Class<?>[] paramTypes = method.getParameterTypes();
if (paramTypes.length == arguments.length) {
int varargIndex = paramTypes.length - 1;

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -102,14 +103,16 @@ class CglibAopProxy implements AopProxy, Serializable {
/** The configuration used to configure this proxy */
protected final AdvisedSupport advised;
@Nullable
protected Object[] constructorArgs;
@Nullable
protected Class<?>[] constructorArgTypes;
/** Dispatcher used for methods on Advised */
private final transient AdvisedDispatcher advisedDispatcher;
private transient Map<String, Integer> fixedInterceptorMap;
private transient Map<String, Integer> fixedInterceptorMap = Collections.emptyMap();
private transient int fixedInterceptorOffset;
@@ -216,7 +219,7 @@ class CglibAopProxy implements AopProxy, Serializable {
protected Object createProxyClassAndInstance(Enhancer enhancer, Callback[] callbacks) {
enhancer.setInterceptDuringConstruction(false);
enhancer.setCallbacks(callbacks);
return (this.constructorArgs != null ?
return (this.constructorArgs != null && this.constructorArgTypes != null ?
enhancer.create(this.constructorArgTypes, this.constructorArgs) :
enhancer.create());
}
@@ -409,6 +412,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static class StaticUnadvisedInterceptor implements MethodInterceptor, Serializable {
@Nullable
private final Object target;
public StaticUnadvisedInterceptor(@Nullable Object target) {
@@ -430,6 +434,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static class StaticUnadvisedExposedInterceptor implements MethodInterceptor, Serializable {
@Nullable
private final Object target;
public StaticUnadvisedExposedInterceptor(@Nullable Object target) {
@@ -520,6 +525,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static class StaticDispatcher implements Dispatcher, Serializable {
@Nullable
private Object target;
public StaticDispatcher(@Nullable Object target) {
@@ -527,6 +533,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
@Override
@Nullable
public Object loadObject() {
return this.target;
}
@@ -610,8 +617,10 @@ class CglibAopProxy implements AopProxy, Serializable {
private final List<Object> adviceChain;
@Nullable
private final Object target;
@Nullable
private final Class<?> targetClass;
public FixedChainStaticTargetInterceptor(
@@ -960,6 +969,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private static class ClassLoaderAwareUndeclaredThrowableStrategy extends UndeclaredThrowableStrategy {
@Nullable
private final ClassLoader classLoader;
public ClassLoaderAwareUndeclaredThrowableStrategy(@Nullable ClassLoader classLoader) {

View File

@@ -46,6 +46,7 @@ import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -101,8 +102,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private String[] interceptorNames;
@Nullable
private String targetName;
private boolean autodetectInterfaces = true;
@@ -113,16 +116,19 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
private boolean freezeProxy = false;
@Nullable
private transient ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader();
private transient boolean classLoaderConfigured = false;
@Nullable
private transient BeanFactory beanFactory;
/** Whether the advisor chain has already been initialized */
private boolean advisorChainInitialized = false;
/** If this is a singleton, the cached singleton proxy instance */
@Nullable
private Object singletonInstance;
@@ -404,6 +410,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* @return {@code true} if it's an Advisor or Advice
*/
private boolean isNamedBeanAnAdvisorOrAdvice(String beanName) {
Assert.state(this.beanFactory != null, "No BeanFactory set");
Class<?> namedBeanClass = this.beanFactory.getType(beanName);
if (namedBeanClass != null) {
return (Advisor.class.isAssignableFrom(namedBeanClass) || Advice.class.isAssignableFrom(namedBeanClass));

View File

@@ -43,6 +43,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
*/
private int order = Ordered.LOWEST_PRECEDENCE;
@Nullable
private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader();
private boolean classLoaderConfigured = false;
@@ -77,6 +78,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
/**
* Return the configured proxy ClassLoader for this processor.
*/
@Nullable
protected ClassLoader getProxyClassLoader() {
return this.proxyClassLoader;
}

View File

@@ -63,17 +63,20 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
protected final Object proxy;
@Nullable
protected final Object target;
protected final Method method;
protected Object[] arguments;
protected Object[] arguments = new Object[0];
@Nullable
private final Class<?> targetClass;
/**
* Lazily initialized map of user-specific attributes for this invocation.
*/
@Nullable
private Map<String, Object> userAttributes;
/**
@@ -103,7 +106,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* but would complicate the code. And it would work only for static pointcuts.
*/
protected ReflectiveMethodInvocation(
Object proxy, @Nullable Object target, Method method, Object[] arguments,
Object proxy, @Nullable Object target, Method method, @Nullable Object[] arguments,
@Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
this.proxy = proxy;
@@ -143,7 +146,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
@Override
public final Object[] getArguments() {
return (this.arguments != null ? this.arguments : new Object[0]);
return this.arguments;
}
@Override
@@ -205,8 +208,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
*/
@Override
public MethodInvocation invocableClone() {
Object[] cloneArguments = null;
if (this.arguments != null) {
Object[] cloneArguments = this.arguments;
if (this.arguments.length > 0) {
// Build an independent copy of the arguments array.
cloneArguments = new Object[this.arguments.length];
System.arraycopy(this.arguments, 0, cloneArguments, 0, this.arguments.length);
@@ -223,7 +226,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* @see java.lang.Object#clone()
*/
@Override
public MethodInvocation invocableClone(@Nullable Object... arguments) {
public MethodInvocation invocableClone(Object... arguments) {
// Force initialization of the user attributes Map,
// for having a shared Map reference in the clone.
if (this.userAttributes == null) {

View File

@@ -97,6 +97,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* Convenience constant for subclasses: Return value for "do not proxy".
* @see #getAdvicesAndAdvisorsForBean
*/
@Nullable
protected static final Object[] DO_NOT_PROXY = null;
/**
@@ -124,8 +125,10 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
private boolean applyCommonInterceptorsFirst = true;
@Nullable
private TargetSourceCreator[] customTargetSourceCreators;
@Nullable
private BeanFactory beanFactory;
private final Set<String> targetSourcedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>(16));

View File

@@ -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.
@@ -21,6 +21,7 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
/**
* Extension of {@link AbstractAutoProxyCreator} which implements {@link BeanFactoryAware},
@@ -39,6 +40,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
public abstract class AbstractBeanFactoryAwareAdvisingPostProcessor extends AbstractAdvisingBeanPostProcessor
implements BeanFactoryAware {
@Nullable
private ConfigurableListableBeanFactory beanFactory;

View File

@@ -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.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanCurrentlyInCreationException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -43,6 +44,7 @@ public class BeanFactoryAdvisorRetrievalHelper {
private final ConfigurableListableBeanFactory beanFactory;
@Nullable
private String[] cachedAdvisorBeanNames;
@@ -95,7 +97,8 @@ public class BeanFactoryAdvisorRetrievalHelper {
Throwable rootCause = ex.getMostSpecificCause();
if (rootCause instanceof BeanCurrentlyInCreationException) {
BeanCreationException bce = (BeanCreationException) rootCause;
if (this.beanFactory.isCurrentlyInCreation(bce.getBeanName())) {
String bceBeanName = bce.getBeanName();
if (bceBeanName != null && this.beanFactory.isCurrentlyInCreation(bceBeanName)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping advisor '" + name +
"' with dependency on currently created bean: " + ex.getMessage());

View File

@@ -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.
@@ -46,6 +46,7 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("serial")
public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
@Nullable
private List<String> beanNames;

View File

@@ -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.aop.framework.autoproxy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.lang.Nullable;
/**
* {@code BeanPostProcessor} implementation that creates AOP proxies based on all
@@ -43,6 +44,7 @@ public class DefaultAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCrea
private boolean usePrefix = false;
@Nullable
private String advisorBeanNamePrefix;
@@ -76,6 +78,7 @@ public class DefaultAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCrea
* Return the prefix for bean names that will cause them to be included
* for auto-proxying by this object.
*/
@Nullable
public String getAdvisorBeanNamePrefix() {
return this.advisorBeanNamePrefix;
}
@@ -96,7 +99,11 @@ public class DefaultAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCrea
*/
@Override
protected boolean isEligibleAdvisorBean(String beanName) {
return (!isUsePrefix() || beanName.startsWith(getAdvisorBeanNamePrefix()));
if (!isUsePrefix()) {
return true;
}
String prefix = getAdvisorBeanNamePrefix();
return (prefix != null && beanName.startsWith(prefix));
}
}

View File

@@ -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.
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.lang.Nullable;
/**
* Base {@code MethodInterceptor} implementation for tracing.
@@ -50,6 +51,7 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser
* The default {@code Log} instance used to write trace messages.
* This instance is mapped to the implementing {@code Class}.
*/
@Nullable
protected transient Log defaultLogger = LogFactory.getLog(getClass());
/**
@@ -83,7 +85,6 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser
* but rather into a specific named category.
* <p><b>NOTE:</b> Specify either this property or "useDynamicLogger", not both.
* @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) {

View File

@@ -72,10 +72,12 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
private final Map<Method, AsyncTaskExecutor> executors = new ConcurrentHashMap<>(16);
@Nullable
private volatile Executor defaultExecutor;
private AsyncUncaughtExceptionHandler exceptionHandler;
@Nullable
private BeanFactory beanFactory;

View File

@@ -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.
@@ -28,6 +28,8 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
@@ -56,9 +58,11 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O
private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource();
/** The name of the target bean */
@Nullable
private String targetBeanName;
/** The cached singleton proxy */
@Nullable
private Object proxy;
@@ -91,6 +95,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig implements FactoryBean<O
pf.copyFrom(this);
pf.setTargetSource(this.scopedTargetSource);
Assert.notNull(this.targetBeanName, "Property 'targetBeanName' is required");
Class<?> beanType = beanFactory.getType(this.targetBeanName);
if (beanType == null) {
throw new IllegalStateException("Cannot create scoped proxy for bean '" + this.targetBeanName +

View File

@@ -43,10 +43,13 @@ import org.springframework.util.Assert;
@SuppressWarnings("serial")
public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware {
@Nullable
private String adviceBeanName;
@Nullable
private BeanFactory beanFactory;
@Nullable
private transient volatile Advice advice;
private transient volatile Object adviceMonitor = new Object();
@@ -119,10 +122,12 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
// reuse the factory's singleton lock, just in case a lazy dependency
// of our advice bean happens to trigger the singleton lock implicitly...
synchronized (this.adviceMonitor) {
if (this.advice == null) {
this.advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
advice = this.advice;
if (advice == null) {
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
this.advice = advice;
}
return this.advice;
return advice;
}
}
}

View File

@@ -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.
@@ -33,8 +33,10 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public abstract class AbstractExpressionPointcut implements ExpressionPointcut, Serializable {
@Nullable
private String location;
@Nullable
private String expression;

View File

@@ -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.
@@ -22,6 +22,7 @@ import org.aopalliance.aop.Advice;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -37,6 +38,7 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial")
public abstract class AbstractPointcutAdvisor implements PointcutAdvisor, Ordered, Serializable {
@Nullable
private Integer order;

View File

@@ -65,7 +65,7 @@ public abstract class AopUtils {
* @see #isJdkDynamicProxy
* @see #isCglibProxy
*/
public static boolean isAopProxy(Object object) {
public static boolean isAopProxy(@Nullable Object object) {
return (object instanceof SpringProxy &&
(Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass())));
}
@@ -78,7 +78,7 @@ public abstract class AopUtils {
* @param object the object to check
* @see java.lang.reflect.Proxy#isProxyClass
*/
public static boolean isJdkDynamicProxy(Object object) {
public static boolean isJdkDynamicProxy(@Nullable Object object) {
return (object instanceof SpringProxy && Proxy.isProxyClass(object.getClass()));
}
@@ -90,7 +90,7 @@ public abstract class AopUtils {
* @param object the object to check
* @see ClassUtils#isCglibProxy(Object)
*/
public static boolean isCglibProxy(Object object) {
public static boolean isCglibProxy(@Nullable Object object) {
return (object instanceof SpringProxy && ClassUtils.isCglibProxy(object));
}

View File

@@ -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,7 +22,6 @@ import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* Convenient class for building up pointcuts. All methods return
@@ -188,21 +187,14 @@ public class ComposablePointcut implements Pointcut, Serializable {
if (!(other instanceof ComposablePointcut)) {
return false;
}
ComposablePointcut that = (ComposablePointcut) other;
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
ComposablePointcut otherPointcut = (ComposablePointcut) other;
return (this.classFilter.equals(otherPointcut.classFilter) &&
this.methodMatcher.equals(otherPointcut.methodMatcher));
}
@Override
public int hashCode() {
int code = 17;
if (this.classFilter != null) {
code = 37 * code + this.classFilter.hashCode();
}
if (this.methodMatcher != null) {
code = 37 * code + this.methodMatcher.hashCode();
}
return code;
return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
}
@Override

View File

@@ -40,6 +40,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
private Class<?> clazz;
@Nullable
private String methodName;
private volatile int evaluations;

View File

@@ -23,7 +23,6 @@ import java.util.LinkedList;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
/**
@@ -105,12 +104,12 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
@Override
public boolean equals(Object other) {
return (this == other || (other instanceof NameMatchMethodPointcut &&
ObjectUtils.nullSafeEquals(this.mappedNames, ((NameMatchMethodPointcut) other).mappedNames)));
this.mappedNames.equals(((NameMatchMethodPointcut) other).mappedNames)));
}
@Override
public int hashCode() {
return (this.mappedNames != null ? this.mappedNames.hashCode() : 0);
return this.mappedNames.hashCode();
}
}

View File

@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -44,8 +45,10 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial")
public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor {
@Nullable
private String[] patterns;
@Nullable
private AbstractRegexpMethodPointcut pointcut;
private final Object pointcutMonitor = new SerializableMonitor();
@@ -121,7 +124,9 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
synchronized (this.pointcutMonitor) {
if (this.pointcut == null) {
this.pointcut = createPointcut();
this.pointcut.setPatterns(this.patterns);
if (this.patterns != null) {
this.pointcut.setPatterns(this.patterns);
}
}
return pointcut;
}

View File

@@ -23,7 +23,6 @@ import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* Simple Pointcut that looks for a specific Java 5 annotation
@@ -127,21 +126,14 @@ public class AnnotationMatchingPointcut implements Pointcut {
if (!(other instanceof AnnotationMatchingPointcut)) {
return false;
}
AnnotationMatchingPointcut that = (AnnotationMatchingPointcut) other;
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
AnnotationMatchingPointcut otherPointcut = (AnnotationMatchingPointcut) other;
return (this.classFilter.equals(otherPointcut.classFilter) &&
this.methodMatcher.equals(otherPointcut.methodMatcher));
}
@Override
public int hashCode() {
int code = 17;
if (this.classFilter != null) {
code = 37 * code + this.classFilter.hashCode();
}
if (this.methodMatcher != null) {
code = 37 * code + this.methodMatcher.hashCode();
}
return code;
return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
}
@Override

View File

@@ -78,15 +78,16 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
private int autoGrowCollectionLimit = Integer.MAX_VALUE;
@Nullable
Object wrappedObject;
private String nestedPath = "";
@Nullable
Object rootObject;
/**
* Map with cached nested Accessors: nested path -> Accessor instance.
*/
/** Map with cached nested Accessors: nested path -> Accessor instance */
@Nullable
private Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors;
@@ -199,7 +200,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
public final Object getWrappedInstance() {
Assert.state(this.wrappedObject != null, "No wrapped instance");
Assert.state(this.wrappedObject != null, "No wrapped object");
return this.wrappedObject;
}
@@ -218,8 +219,8 @@ 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() {
Assert.state(this.rootObject != null, "No root object");
return this.rootObject;
}
@@ -228,8 +229,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @see #getNestedPath
*/
public final Class<?> getRootClass() {
Assert.state(this.wrappedObject != null, "No root object");
return this.rootObject.getClass();
return getRootInstance().getClass();
}
@Override
@@ -287,6 +287,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
throw new InvalidPropertyException(
getRootClass(), this.nestedPath + tokens.actualName, "No property handler found");
}
Assert.state(tokens.keys != null, "No token keys");
String lastKey = tokens.keys[tokens.keys.length - 1];
if (propValue.getClass().isArray()) {
@@ -379,9 +380,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
private Object getPropertyHoldingValue(PropertyTokenHolder tokens) {
// Apply indexes and map keys: fetch value for all keys but the last one.
PropertyTokenHolder getterTokens = new PropertyTokenHolder();
Assert.state(tokens.keys != null, "No token keys");
PropertyTokenHolder getterTokens = new PropertyTokenHolder(tokens.actualName);
getterTokens.canonicalName = tokens.canonicalName;
getterTokens.actualName = tokens.actualName;
getterTokens.keys = new String[tokens.keys.length - 1];
System.arraycopy(tokens.keys, 0, getterTokens.keys, 0, tokens.keys.length - 1);
@@ -461,7 +462,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
catch (InvocationTargetException ex) {
PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent(
this.rootObject, this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
getRootInstance(), this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
if (ex.getTargetException() instanceof ClassCastException) {
throw new TypeMismatchException(propertyChangeEvent, ph.getPropertyType(), ex.getTargetException());
}
@@ -476,7 +477,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
catch (Exception ex) {
PropertyChangeEvent pce = new PropertyChangeEvent(
this.rootObject, this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
getRootInstance(), this.nestedPath + tokens.canonicalName, oldValue, pv.getValue());
throw new MethodInvocationException(pce, ex);
}
}
@@ -582,12 +583,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
catch (ConverterNotFoundException | IllegalStateException ex) {
PropertyChangeEvent pce =
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
new PropertyChangeEvent(getRootInstance(), this.nestedPath + propertyName, oldValue, newValue);
throw new ConversionNotSupportedException(pce, requiredType, ex);
}
catch (ConversionException | IllegalArgumentException ex) {
PropertyChangeEvent pce =
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
new PropertyChangeEvent(getRootInstance(), this.nestedPath + propertyName, oldValue, newValue);
throw new TypeMismatchException(pce, requiredType, ex);
}
}
@@ -621,7 +622,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
if (tokens.keys != null) {
if (value == null) {
if (isAutoGrowNestedPaths()) {
value = setDefaultValue(tokens.actualName);
value = setDefaultValue(new PropertyTokenHolder(tokens.actualName));
}
else {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
@@ -865,13 +866,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return nestedPa;
}
private Object setDefaultValue(String propertyName) {
PropertyTokenHolder tokens = new PropertyTokenHolder();
tokens.actualName = propertyName;
tokens.canonicalName = propertyName;
return setDefaultValue(tokens);
}
private Object setDefaultValue(PropertyTokenHolder tokens) {
PropertyValue pv = createDefaultPropertyValue(tokens);
setPropertyValue(tokens, pv);
@@ -932,7 +926,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @return representation of the parsed property tokens
*/
private PropertyTokenHolder getPropertyNameTokens(String propertyName) {
PropertyTokenHolder tokens = new PropertyTokenHolder();
String actualName = null;
List<String> keys = new ArrayList<>(2);
int searchIndex = 0;
@@ -955,8 +948,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
}
}
tokens.actualName = (actualName != null ? actualName : propertyName);
tokens.canonicalName = tokens.actualName;
PropertyTokenHolder tokens = new PropertyTokenHolder(actualName != null ? actualName : propertyName);
if (!keys.isEmpty()) {
tokens.canonicalName += PROPERTY_KEY_PREFIX +
StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX) +
@@ -1036,10 +1028,16 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
protected static class PropertyTokenHolder {
public String canonicalName;
public PropertyTokenHolder(String name) {
this.actualName = name;
this.canonicalName = name;
}
public String actualName;
public String canonicalName;
@Nullable
public String[] keys;
}

View File

@@ -31,8 +31,10 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
private final String name;
@Nullable
private final Object value;
@Nullable
private Object source;
@@ -58,6 +60,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
/**
* Return the value of the attribute.
*/
@Nullable
public Object getValue() {
return this.value;
}
@@ -71,6 +74,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -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.
@@ -30,6 +30,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement {
@Nullable
private Object source;
@@ -42,6 +43,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -499,7 +499,9 @@ public abstract class BeanUtils {
return new MethodParameter(((GenericTypeAwarePropertyDescriptor) pd).getWriteMethodParameter());
}
else {
return new MethodParameter(pd.getWriteMethod(), 0);
Method writeMethod = pd.getWriteMethod();
Assert.state(writeMethod != null, "No write method available");
return new MethodParameter(writeMethod, 0);
}
}

View File

@@ -66,11 +66,13 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* Cached introspections results for this object, to prevent encountering
* the cost of JavaBeans introspection every time.
*/
@Nullable
private CachedIntrospectionResults cachedIntrospectionResults;
/**
* The security context used for invoking the property methods
*/
@Nullable
private AccessControlContext acc;
@@ -178,7 +180,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* Set the security context used during the invocation of the wrapped instance methods.
* Can be null.
*/
public void setSecurityContext(AccessControlContext acc) {
public void setSecurityContext(@Nullable AccessControlContext acc) {
this.acc = acc;
}
@@ -186,6 +188,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* Return the security context used during the invocation of the wrapped instance methods.
* Can be null.
*/
@Nullable
public AccessControlContext getSecurityContext() {
return this.acc;
}

View File

@@ -261,12 +261,16 @@ class ExtendedBeanInfo implements BeanInfo {
static class SimplePropertyDescriptor extends PropertyDescriptor {
@Nullable
private Method readMethod;
@Nullable
private Method writeMethod;
@Nullable
private Class<?> propertyType;
@Nullable
private Class<?> propertyEditorClass;
public SimplePropertyDescriptor(PropertyDescriptor original) throws IntrospectionException {
@@ -282,6 +286,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getReadMethod() {
return this.readMethod;
}
@@ -292,6 +297,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getWriteMethod() {
return this.writeMethod;
}
@@ -315,6 +321,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}
@@ -345,18 +352,25 @@ class ExtendedBeanInfo implements BeanInfo {
static class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
@Nullable
private Method readMethod;
@Nullable
private Method writeMethod;
@Nullable
private Class<?> propertyType;
@Nullable
private Method indexedReadMethod;
@Nullable
private Method indexedWriteMethod;
@Nullable
private Class<?> indexedPropertyType;
@Nullable
private Class<?> propertyEditorClass;
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
@@ -379,6 +393,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getReadMethod() {
return this.readMethod;
}
@@ -389,6 +404,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getWriteMethod() {
return this.writeMethod;
}
@@ -412,6 +428,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getIndexedReadMethod() {
return this.indexedReadMethod;
}
@@ -422,6 +439,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getIndexedWriteMethod() {
return this.indexedWriteMethod;
}
@@ -446,6 +464,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}

View File

@@ -28,6 +28,7 @@ import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
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;
@@ -44,14 +45,19 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
private final Class<?> beanClass;
@Nullable
private final Method readMethod;
@Nullable
private final Method writeMethod;
@Nullable
private volatile Set<Method> ambiguousWriteMethods;
@Nullable
private MethodParameter writeMethodParameter;
@Nullable
private Class<?> propertyType;
private final Class<?> propertyEditorClass;
@@ -116,16 +122,19 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
}
@Override
@Nullable
public Method getReadMethod() {
return this.readMethod;
}
@Override
@Nullable
public Method getWriteMethod() {
return this.writeMethod;
}
public Method getWriteMethodForActualAccess() {
Assert.state(this.writeMethod != null, "No write method available");
Set<Method> ambiguousCandidates = this.ambiguousWriteMethods;
if (ambiguousCandidates != null) {
this.ambiguousWriteMethods = null;
@@ -137,10 +146,12 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
}
public MethodParameter getWriteMethodParameter() {
Assert.state(this.writeMethodParameter != null, "No write method available");
return this.writeMethodParameter;
}
@Override
@Nullable
public Class<?> getPropertyType() {
return this.propertyType;
}

View File

@@ -41,6 +41,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
private final List<PropertyValue> propertyValueList;
@Nullable
private Set<String> processedProperties;
private volatile boolean converted = false;

View File

@@ -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.
@@ -29,7 +29,8 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class NotWritablePropertyException extends InvalidPropertyException {
private String[] possibleMatches = null;
@Nullable
private String[] possibleMatches;
/**

View File

@@ -30,6 +30,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public abstract class PropertyAccessException extends BeansException {
@Nullable
private transient PropertyChangeEvent propertyChangeEvent;

View File

@@ -91,20 +91,26 @@ import org.springframework.util.ClassUtils;
*/
public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@Nullable
private ConversionService conversionService;
private boolean defaultEditorsActive = false;
private boolean configValueEditorsActive = false;
@Nullable
private Map<Class<?>, PropertyEditor> defaultEditors;
@Nullable
private Map<Class<?>, PropertyEditor> overriddenDefaultEditors;
@Nullable
private Map<Class<?>, PropertyEditor> customEditors;
@Nullable
private Map<String, CustomEditorHolder> customEditorsForPath;
@Nullable
private Map<Class<?>, PropertyEditor> customEditorCache;
@@ -378,7 +384,8 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
*/
@Nullable
private PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
CustomEditorHolder holder =
(this.customEditorsForPath != null ? this.customEditorsForPath.get(propertyName) : null);
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
}
@@ -517,6 +524,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private final PropertyEditor propertyEditor;
@Nullable
private final Class<?> registeredType;
private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class<?> registeredType) {

View File

@@ -44,18 +44,22 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
private final String name;
@Nullable
private final Object value;
private boolean optional = false;
private boolean converted = false;
@Nullable
private Object convertedValue;
/** Package-visible field that indicates whether conversion is necessary */
@Nullable
volatile Boolean conversionNecessary;
/** Package-visible field for caching the resolved property path tokens */
@Nullable
transient volatile Object resolvedTokens;
@@ -177,6 +181,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
* Return the converted value of the constructor argument,
* after processed type conversion.
*/
@Nullable
public synchronized Object getConvertedValue() {
return this.convertedValue;
}

View File

@@ -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.
@@ -59,6 +59,7 @@ class TypeConverterDelegate {
private final PropertyEditorRegistrySupport propertyEditorRegistry;
@Nullable
private final Object targetObject;
@@ -314,7 +315,7 @@ class TypeConverterDelegate {
private Object attemptToConvertStringToEnum(Class<?> requiredType, String trimmedValue, Object currentConvertedValue) {
Object convertedValue = currentConvertedValue;
if (Enum.class == requiredType) {
if (Enum.class == requiredType && this.targetObject != null) {
// target type is declared as raw enum, treat the trimmed value as <enum.fqn>.FIELD_NAME
int index = trimmedValue.lastIndexOf(".");
if (index > - 1) {

View File

@@ -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.
@@ -36,8 +36,10 @@ public class TypeMismatchException extends PropertyAccessException {
public static final String ERROR_CODE = "typeMismatch";
@Nullable
private transient Object value;
@Nullable
private Class<?> requiredType;
@@ -99,6 +101,7 @@ public class TypeMismatchException extends PropertyAccessException {
* Return the offending value (may be {@code null}).
*/
@Override
@Nullable
public Object getValue() {
return this.value;
}

View File

@@ -34,10 +34,13 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanCreationException extends FatalBeanException {
@Nullable
private String beanName;
@Nullable
private String resourceDescription;
@Nullable
private List<Throwable> relatedCauses;
@@ -119,6 +122,7 @@ public class BeanCreationException extends FatalBeanException {
/**
* Return the name of the bean requested, if any.
*/
@Nullable
public String getBeanName() {
return this.beanName;
}

View File

@@ -30,8 +30,10 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanDefinitionStoreException extends FatalBeanException {
@Nullable
private String resourceDescription;
@Nullable
private String beanName;

View File

@@ -29,10 +29,13 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class CannotLoadBeanClassException extends FatalBeanException {
@Nullable
private String resourceDescription;
@Nullable
private String beanName;
@Nullable
private String beanClassName;
@@ -78,6 +81,7 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* Return the description of the resource that the bean
* definition came from.
*/
@Nullable
public String getResourceDescription() {
return this.resourceDescription;
}
@@ -85,6 +89,7 @@ public class CannotLoadBeanClassException extends FatalBeanException {
/**
* Return the name of the bean requested.
*/
@Nullable
public String getBeanName() {
return this.beanName;
}
@@ -92,6 +97,7 @@ public class CannotLoadBeanClassException extends FatalBeanException {
/**
* Return the name of the class we were trying to load.
*/
@Nullable
public String getBeanClassName() {
return this.beanClassName;
}

View File

@@ -24,6 +24,7 @@ import java.lang.reflect.Member;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* A simple descriptor for an injection point, pointing to a method/constructor
@@ -36,10 +37,13 @@ import org.springframework.util.Assert;
*/
public class InjectionPoint {
@Nullable
protected MethodParameter methodParameter;
@Nullable
protected Field field;
@Nullable
private volatile Annotation[] fieldAnnotations;
@@ -99,18 +103,31 @@ public class InjectionPoint {
return this.field;
}
/**
* Return the wrapped MethodParameter, assuming it is present.
* @return the MethodParameter (never {@code null})
* @throws IllegalStateException if no MethodParameter is available
* @since 5.0
*/
protected final MethodParameter obtainMethodParameter() {
Assert.state(this.methodParameter != null, "Neither Field nor MethodParameter");
return this.methodParameter;
}
/**
* Obtain the annotations associated with the wrapped field or method/constructor parameter.
*/
public Annotation[] getAnnotations() {
if (this.field != null) {
if (this.fieldAnnotations == null) {
this.fieldAnnotations = this.field.getAnnotations();
Annotation[] fieldAnnotations = this.fieldAnnotations;
if (fieldAnnotations == null) {
fieldAnnotations = this.field.getAnnotations();
this.fieldAnnotations = fieldAnnotations;
}
return this.fieldAnnotations;
return fieldAnnotations;
}
else {
return this.methodParameter.getParameterAnnotations();
return obtainMethodParameter().getParameterAnnotations();
}
}
@@ -123,7 +140,7 @@ public class InjectionPoint {
@Nullable
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
return (this.field != null ? this.field.getAnnotation(annotationType) :
this.methodParameter.getParameterAnnotation(annotationType));
obtainMethodParameter().getParameterAnnotation(annotationType));
}
/**
@@ -131,7 +148,7 @@ public class InjectionPoint {
* indicating the injection type.
*/
public Class<?> getDeclaredType() {
return (this.field != null ? this.field.getType() : this.methodParameter.getParameterType());
return (this.field != null ? this.field.getType() : obtainMethodParameter().getParameterType());
}
/**
@@ -139,7 +156,7 @@ public class InjectionPoint {
* @return the Field / Method / Constructor as Member
*/
public Member getMember() {
return (this.field != null ? this.field : this.methodParameter.getMember());
return (this.field != null ? this.field : obtainMethodParameter().getMember());
}
/**
@@ -152,7 +169,7 @@ public class InjectionPoint {
* @return the Field / Method / Constructor as AnnotatedElement
*/
public AnnotatedElement getAnnotatedElement() {
return (this.field != null ? this.field : this.methodParameter.getAnnotatedElement());
return (this.field != null ? this.field : obtainMethodParameter().getAnnotatedElement());
}
@@ -165,18 +182,18 @@ public class InjectionPoint {
return false;
}
InjectionPoint otherPoint = (InjectionPoint) other;
return (this.field != null ? this.field.equals(otherPoint.field) :
this.methodParameter.equals(otherPoint.methodParameter));
return (ObjectUtils.nullSafeEquals(this.field, otherPoint.field) &&
ObjectUtils.nullSafeEquals(this.methodParameter, otherPoint.methodParameter));
}
@Override
public int hashCode() {
return (this.field != null ? this.field.hashCode() : this.methodParameter.hashCode());
return (this.field != null ? this.field.hashCode() : ObjectUtils.nullSafeHashCode(this.methodParameter));
}
@Override
public String toString() {
return (this.field != null ? "field '" + this.field.getName() + "'" : this.methodParameter.toString());
return (this.field != null ? "field '" + this.field.getName() + "'" : String.valueOf(this.methodParameter));
}
}

View File

@@ -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,8 +35,10 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class NoSuchBeanDefinitionException extends BeansException {
@Nullable
private String beanName;
@Nullable
private ResolvableType resolvableType;

View File

@@ -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.
@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("serial")
public class UnsatisfiedDependencyException extends BeanCreationException {
@Nullable
private InjectionPoint injectionPoint;

View File

@@ -128,6 +128,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private int order = Ordered.LOWEST_PRECEDENCE - 2;
@Nullable
private ConfigurableListableBeanFactory beanFactory;
private final Set<String> lookupMethodsChecked = Collections.newSetFromMap(new ConcurrentHashMap<>(256));
@@ -242,6 +243,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
ReflectionUtils.doWithMethods(beanClass, method -> {
Lookup lookup = method.getAnnotation(Lookup.class);
if (lookup != null) {
Assert.state(beanFactory != null, "No BeanFactory available");
LookupOverride override = new LookupOverride(method, lookup.value());
try {
RootBeanDefinition mbd = (RootBeanDefinition) beanFactory.getMergedBeanDefinition(beanName);
@@ -504,7 +506,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private void registerDependentBeans(@Nullable String beanName, Set<String> autowiredBeanNames) {
if (beanName != null) {
for (String autowiredBeanName : autowiredBeanNames) {
if (this.beanFactory.containsBean(autowiredBeanName)) {
if (this.beanFactory != null && this.beanFactory.containsBean(autowiredBeanName)) {
this.beanFactory.registerDependentBean(autowiredBeanName, beanName);
}
if (logger.isDebugEnabled()) {
@@ -519,9 +521,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
* Resolve the specified cached method argument or field value.
*/
@Nullable
private Object resolvedCachedArgument(@Nullable String beanName, Object cachedArgument) {
private Object resolvedCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) {
if (cachedArgument instanceof DependencyDescriptor) {
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
Assert.state(beanFactory != null, "No BeanFactory available");
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
}
else {
@@ -539,6 +542,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private volatile boolean cached = false;
@Nullable
private volatile Object cachedFieldValue;
public AutowiredFieldElement(Field field, boolean required) {
@@ -557,6 +561,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
DependencyDescriptor desc = new DependencyDescriptor(field, this.required);
desc.setContainingClass(bean.getClass());
Set<String> autowiredBeanNames = new LinkedHashSet<>(1);
Assert.state(beanFactory != null, "No BeanFactory available");
TypeConverter typeConverter = beanFactory.getTypeConverter();
try {
value = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);
@@ -603,6 +608,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private volatile boolean cached = false;
@Nullable
private volatile Object[] cachedMethodArguments;
public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
@@ -626,6 +632,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
arguments = new Object[paramTypes.length];
DependencyDescriptor[] descriptors = new DependencyDescriptor[paramTypes.length];
Set<String> autowiredBeans = new LinkedHashSet<>(paramTypes.length);
Assert.state(beanFactory != null, "No BeanFactory available");
TypeConverter typeConverter = beanFactory.getTypeConverter();
for (int i = 0; i < arguments.length; i++) {
MethodParameter methodParam = new MethodParameter(method, i);
@@ -647,9 +654,9 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
synchronized (this) {
if (!this.cached) {
if (arguments != null) {
this.cachedMethodArguments = new Object[paramTypes.length];
Object[] cachedMethodArguments = new Object[paramTypes.length];
for (int i = 0; i < arguments.length; i++) {
this.cachedMethodArguments[i] = descriptors[i];
cachedMethodArguments[i] = descriptors[i];
}
registerDependentBeans(beanName, autowiredBeans);
if (autowiredBeans.size() == paramTypes.length) {
@@ -658,12 +665,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
String autowiredBeanName = it.next();
if (beanFactory.containsBean(autowiredBeanName)) {
if (beanFactory.isTypeMatch(autowiredBeanName, paramTypes[i])) {
this.cachedMethodArguments[i] = new ShortcutDependencyDescriptor(
cachedMethodArguments[i] = new ShortcutDependencyDescriptor(
descriptors[i], autowiredBeanName, paramTypes[i]);
}
}
}
}
this.cachedMethodArguments = cachedMethodArguments;
}
else {
this.cachedMethodArguments = null;
@@ -685,12 +693,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@Nullable
private Object[] resolveCachedArguments(@Nullable String beanName) {
if (this.cachedMethodArguments == null) {
Object[] cachedMethodArguments = this.cachedMethodArguments;
if (cachedMethodArguments == null) {
return null;
}
Object[] arguments = new Object[this.cachedMethodArguments.length];
Object[] arguments = new Object[cachedMethodArguments.length];
for (int i = 0; i < arguments.length; i++) {
arguments[i] = resolvedCachedArgument(beanName, this.cachedMethodArguments[i]);
arguments[i] = resolvedCachedArgument(beanName, cachedMethodArguments[i]);
}
return arguments;
}

View File

@@ -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.
@@ -51,8 +51,10 @@ public class CustomAutowireConfigurer implements BeanFactoryPostProcessor, BeanC
private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered
@Nullable
private Set<?> customQualifierTypes;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();

View File

@@ -40,6 +40,7 @@ import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcess
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -77,14 +78,16 @@ public class InitDestroyAnnotationBeanPostProcessor
protected transient Log logger = LogFactory.getLog(getClass());
@Nullable
private Class<? extends Annotation> initAnnotationType;
@Nullable
private Class<? extends Annotation> destroyAnnotationType;
private int order = Ordered.LOWEST_PRECEDENCE;
private transient final Map<Class<?>, LifecycleMetadata> lifecycleMetadataCache =
new ConcurrentHashMap<>(256);
@Nullable
private transient final Map<Class<?>, LifecycleMetadata> lifecycleMetadataCache = new ConcurrentHashMap<>(256);
/**
@@ -255,8 +258,10 @@ public class InitDestroyAnnotationBeanPostProcessor
private final Collection<LifecycleElement> destroyMethods;
@Nullable
private volatile Set<LifecycleElement> checkedInitMethods;
@Nullable
private volatile Set<LifecycleElement> checkedDestroyMethods;
public LifecycleMetadata(Class<?> targetClass, Collection<LifecycleElement> initMethods,
@@ -295,8 +300,9 @@ public class InitDestroyAnnotationBeanPostProcessor
}
public void invokeInitMethods(Object target, String beanName) throws Throwable {
Collection<LifecycleElement> checkedInitMethods = this.checkedInitMethods;
Collection<LifecycleElement> initMethodsToIterate =
(this.checkedInitMethods != null ? this.checkedInitMethods : this.initMethods);
(checkedInitMethods != null ? checkedInitMethods : this.initMethods);
if (!initMethodsToIterate.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (LifecycleElement element : initMethodsToIterate) {
@@ -309,8 +315,9 @@ public class InitDestroyAnnotationBeanPostProcessor
}
public void invokeDestroyMethods(Object target, String beanName) throws Throwable {
Collection<LifecycleElement> checkedDestroyMethods = this.checkedDestroyMethods;
Collection<LifecycleElement> destroyMethodsToUse =
(this.checkedDestroyMethods != null ? this.checkedDestroyMethods : this.destroyMethods);
(checkedDestroyMethods != null ? checkedDestroyMethods : this.destroyMethods);
if (!destroyMethodsToUse.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (LifecycleElement element : destroyMethodsToUse) {
@@ -323,8 +330,9 @@ public class InitDestroyAnnotationBeanPostProcessor
}
public boolean hasDestroyMethods() {
Collection<LifecycleElement> checkedDestroyMethods = this.checkedDestroyMethods;
Collection<LifecycleElement> destroyMethodsToUse =
(this.checkedDestroyMethods != null ? this.checkedDestroyMethods : this.destroyMethods);
(checkedDestroyMethods != null ? checkedDestroyMethods : this.destroyMethods);
return !destroyMethodsToUse.isEmpty();
}
}

View File

@@ -53,6 +53,7 @@ public class InjectionMetadata {
private final Collection<InjectedElement> injectedElements;
@Nullable
private volatile Set<InjectedElement> checkedElements;
@@ -78,8 +79,9 @@ public class InjectionMetadata {
}
public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
Collection<InjectedElement> checkedElements = this.checkedElements;
Collection<InjectedElement> elementsToIterate =
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
(checkedElements != null ? checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (InjectedElement element : elementsToIterate) {
@@ -95,8 +97,9 @@ public class InjectionMetadata {
* @since 3.2.13
*/
public void clear(@Nullable PropertyValues pvs) {
Collection<InjectedElement> checkedElements = this.checkedElements;
Collection<InjectedElement> elementsToIterate =
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
(checkedElements != null ? checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) {
for (InjectedElement element : elementsToIterate) {
element.clearPropertySkipping(pvs);
@@ -116,8 +119,10 @@ public class InjectionMetadata {
protected final boolean isField;
@Nullable
protected final PropertyDescriptor pd;
@Nullable
protected volatile Boolean skip;
protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
@@ -192,16 +197,18 @@ public class InjectionMetadata {
* affected property as processed for other processors to ignore it.
*/
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
if (this.skip != null) {
return this.skip;
Boolean skip = this.skip;
if (skip != null) {
return skip;
}
if (pvs == null) {
this.skip = false;
return false;
}
synchronized (pvs) {
if (this.skip != null) {
return this.skip;
skip = this.skip;
if (skip != null) {
return skip;
}
if (this.pd != null) {
if (pvs.contains(this.pd.getName())) {

View File

@@ -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.
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -66,14 +67,18 @@ public abstract class AbstractFactoryBean<T>
private boolean singleton = true;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@Nullable
private BeanFactory beanFactory;
private boolean initialized = false;
@Nullable
private T singletonInstance;
@Nullable
private T earlySingletonInstance;
@@ -103,6 +108,7 @@ public abstract class AbstractFactoryBean<T>
/**
* Return the BeanFactory that this bean runs in.
*/
@Nullable
protected BeanFactory getBeanFactory() {
return this.beanFactory;
}
@@ -176,10 +182,9 @@ public abstract class AbstractFactoryBean<T>
* @return the singleton instance that this FactoryBean holds
* @throws IllegalStateException if the singleton instance is not initialized
*/
@Nullable
private T getSingletonInstance() throws IllegalStateException {
if (!this.initialized) {
throw new IllegalStateException("Singleton instance not initialized yet");
}
Assert.state(this.initialized, "Singleton instance not initialized yet");
return this.singletonInstance;
}
@@ -241,7 +246,7 @@ public abstract class AbstractFactoryBean<T>
* @throws Exception in case of shutdown errors
* @see #createInstance()
*/
protected void destroyInstance(T instance) throws Exception {
protected void destroyInstance(@Nullable T instance) throws Exception {
}

View File

@@ -43,6 +43,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
private final String beanName;
@Nullable
private final String[] aliases;

View File

@@ -47,6 +47,7 @@ import org.springframework.util.StringValueResolver;
*/
public class BeanDefinitionVisitor {
@Nullable
private StringValueResolver valueResolver;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 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.
@@ -29,6 +29,7 @@ public class BeanExpressionContext {
private final ConfigurableBeanFactory beanFactory;
@Nullable
private final Scope scope;
@@ -42,6 +43,7 @@ public class BeanExpressionContext {
return this.beanFactory;
}
@Nullable
public final Scope getScope() {
return this.scope;
}

View File

@@ -91,6 +91,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
/**
* Return this factory's class loader for loading bean classes.
*/
@Nullable
ClassLoader getBeanClassLoader();
/**

View File

@@ -435,16 +435,21 @@ public class ConstructorArgumentValues {
*/
public static class ValueHolder implements BeanMetadataElement {
@Nullable
private Object value;
@Nullable
private String type;
@Nullable
private String name;
@Nullable
private Object source;
private boolean converted = false;
@Nullable
private Object convertedValue;
/**
@@ -558,6 +563,7 @@ public class ConstructorArgumentValues {
* Return the converted value of the constructor argument,
* after processed type conversion.
*/
@Nullable
public synchronized Object getConvertedValue() {
return this.convertedValue;
}

View File

@@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -98,8 +99,10 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered
private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered
@Nullable
private PropertyEditorRegistrar[] propertyEditorRegistrars;
@Nullable
private Map<Class<?>, Class<? extends PropertyEditor>> customEditors;

View File

@@ -46,10 +46,12 @@ import org.springframework.util.ClassUtils;
*/
public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered {
@Nullable
private Map<String, Object> scopes;
private int order = Ordered.LOWEST_PRECEDENCE;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();

View File

@@ -58,12 +58,15 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
private final Class<?> declaringClass;
@Nullable
private String methodName;
@Nullable
private Class<?>[] parameterTypes;
private int parameterIndex;
@Nullable
private String fieldName;
private final boolean required;
@@ -72,8 +75,10 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
private int nestingLevel = 1;
@Nullable
private Class<?> containingClass;
@Nullable
private volatile ResolvableType resolvableType;
@@ -98,8 +103,8 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
super(methodParameter);
this.declaringClass = methodParameter.getDeclaringClass();
if (this.methodParameter.getMethod() != null) {
this.methodName = this.methodParameter.getMethod().getName();
if (methodParameter.getMethod() != null) {
this.methodName = methodParameter.getMethod().getName();
}
this.parameterTypes = methodParameter.getExecutable().getParameterTypes();
this.parameterIndex = methodParameter.getParameterIndex();
@@ -170,7 +175,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
(kotlinPresent && KotlinDelegate.isNullable(this.field)));
}
else {
return !this.methodParameter.isOptional();
return !obtainMethodParameter().isOptional();
}
}
@@ -282,12 +287,14 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
* @since 4.0
*/
public ResolvableType getResolvableType() {
if (this.resolvableType == null) {
this.resolvableType = (this.field != null ?
ResolvableType resolvableType = this.resolvableType;
if (resolvableType == null) {
resolvableType = (this.field != null ?
ResolvableType.forField(this.field, this.nestingLevel, this.containingClass) :
ResolvableType.forMethodParameter(this.methodParameter));
ResolvableType.forMethodParameter(obtainMethodParameter()));
this.resolvableType = resolvableType;
}
return this.resolvableType;
return resolvableType;
}
/**
@@ -333,7 +340,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
*/
@Nullable
public String getDependencyName() {
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
return (this.field != null ? this.field.getName() : obtainMethodParameter().getParameterName());
}
/**
@@ -367,7 +374,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
}
}
else {
return this.methodParameter.getNestedParameterType();
return obtainMethodParameter().getNestedParameterType();
}
}

View File

@@ -16,6 +16,7 @@
package org.springframework.beans.factory.config;
import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
/**
@@ -37,6 +38,7 @@ public class EmbeddedValueResolver implements StringValueResolver {
private final BeanExpressionContext exprContext;
@Nullable
private final BeanExpressionResolver exprResolver;

View File

@@ -24,6 +24,8 @@ import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -55,19 +57,26 @@ import org.springframework.util.StringUtils;
public class FieldRetrievingFactoryBean
implements FactoryBean<Object>, BeanNameAware, BeanClassLoaderAware, InitializingBean {
@Nullable
private Class<?> targetClass;
@Nullable
private Object targetObject;
@Nullable
private String targetField;
@Nullable
private String staticField;
@Nullable
private String beanName;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
// the field we will retrieve
@Nullable
private Field fieldObject;
@@ -85,6 +94,7 @@ public class FieldRetrievingFactoryBean
/**
* Return the target class on which the field is defined.
*/
@Nullable
public Class<?> getTargetClass() {
return targetClass;
}
@@ -103,6 +113,7 @@ public class FieldRetrievingFactoryBean
/**
* Return the target object on which the field is defined.
*/
@Nullable
public Object getTargetObject() {
return this.targetObject;
}
@@ -121,6 +132,7 @@ public class FieldRetrievingFactoryBean
/**
* Return the name of the field to be retrieved.
*/
@Nullable
public String getTargetField() {
return this.targetField;
}
@@ -168,6 +180,7 @@ public class FieldRetrievingFactoryBean
// If no other property specified, consider bean name as static field expression.
if (this.staticField == null) {
this.staticField = this.beanName;
Assert.state(this.staticField != null, "No target field specified");
}
// Try to parse static field into class and field.

View File

@@ -35,9 +35,11 @@ import org.springframework.lang.Nullable;
*/
public class ListFactoryBean extends AbstractFactoryBean<List<Object>> {
@Nullable
private List<?> sourceList;
@SuppressWarnings("rawtypes")
@Nullable
private Class<? extends List> targetListClass;

View File

@@ -35,9 +35,11 @@ import org.springframework.lang.Nullable;
*/
public class MapFactoryBean extends AbstractFactoryBean<Map<Object, Object>> {
@Nullable
private Map<?, ?> sourceMap;
@SuppressWarnings("rawtypes")
@Nullable
private Class<? extends Map> targetMapClass;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-20147 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,8 +67,10 @@ import org.springframework.util.ClassUtils;
public class MethodInvokingBean extends ArgumentConvertingMethodInvoker
implements BeanClassLoaderAware, BeanFactoryAware, InitializingBean {
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@Nullable
private ConfigurableBeanFactory beanFactory;

View File

@@ -18,6 +18,7 @@ package org.springframework.beans.factory.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.lang.Nullable;
/**
* {@link FactoryBean} which returns a value which is the result of a static or instance
@@ -87,6 +88,7 @@ public class MethodInvokingFactoryBean extends MethodInvokingBean implements Fac
private boolean initialized = false;
/** Method call result in the singleton case */
@Nullable
private Object singletonObject;

View File

@@ -17,7 +17,6 @@
package org.springframework.beans.factory.config;
import org.springframework.beans.factory.NamedBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -39,7 +38,7 @@ public class NamedBeanHolder<T> implements NamedBean {
* @param beanName the name of the bean
* @param beanInstance the corresponding bean instance
*/
public NamedBeanHolder(String beanName, @Nullable T beanInstance) {
public NamedBeanHolder(String beanName, T beanInstance) {
Assert.notNull(beanName, "Bean name must not be null");
this.beanName = beanName;
this.beanInstance = beanInstance;

View File

@@ -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.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -96,6 +97,7 @@ import org.springframework.util.Assert;
*/
public class ObjectFactoryCreatingFactoryBean extends AbstractFactoryBean<ObjectFactory<Object>> {
@Nullable
private String targetBeanName;
@@ -124,7 +126,10 @@ public class ObjectFactoryCreatingFactoryBean extends AbstractFactoryBean<Object
@Override
protected ObjectFactory<Object> createInstance() {
return new TargetBeanObjectFactory(getBeanFactory(), this.targetBeanName);
BeanFactory beanFactory = getBeanFactory();
Assert.state(beanFactory != null, "No BeanFactory available");
Assert.state(this.targetBeanName != null, "No target bean name specified");
return new TargetBeanObjectFactory(beanFactory, this.targetBeanName);
}

View File

@@ -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.
@@ -106,16 +106,20 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi
protected String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;
/** Defaults to {@value #DEFAULT_VALUE_SEPARATOR} */
@Nullable
protected String valueSeparator = DEFAULT_VALUE_SEPARATOR;
protected boolean trimValues = false;
@Nullable
protected String nullValue;
protected boolean ignoreUnresolvablePlaceholders = false;
@Nullable
private String beanName;
@Nullable
private BeanFactory beanFactory;

View File

@@ -45,13 +45,15 @@ import org.springframework.lang.Nullable;
*/
public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements InitializingBean {
@Nullable
private String systemTreePath;
@Nullable
private String userTreePath;
private Preferences systemPrefs;
private Preferences systemPrefs = Preferences.systemRoot();
private Preferences userPrefs;
private Preferences userPrefs = Preferences.userRoot();
/**
@@ -77,10 +79,12 @@ public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigu
*/
@Override
public void afterPropertiesSet() {
this.systemPrefs = (this.systemTreePath != null) ?
Preferences.systemRoot().node(this.systemTreePath) : Preferences.systemRoot();
this.userPrefs = (this.userTreePath != null) ?
Preferences.userRoot().node(this.userTreePath) : Preferences.userRoot();
if (this.systemTreePath != null) {
this.systemPrefs = this.systemPrefs.node(this.systemTreePath);
}
if (this.userTreePath != null) {
this.userPrefs = this.userPrefs.node(this.userTreePath);
}
}
/**

View File

@@ -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.
@@ -27,6 +27,8 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -85,16 +87,22 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
private static final Log logger = LogFactory.getLog(PropertyPathFactoryBean.class);
@Nullable
private BeanWrapper targetBeanWrapper;
@Nullable
private String targetBeanName;
@Nullable
private String propertyPath;
@Nullable
private Class<?> resultType;
@Nullable
private String beanName;
@Nullable
private BeanFactory beanFactory;
@@ -168,7 +176,7 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
}
// No other properties specified: check bean name.
int dotIndex = this.beanName.indexOf('.');
int dotIndex = (this.beanName != null ? this.beanName.indexOf('.') : -1);
if (dotIndex == -1) {
throw new IllegalArgumentException(
"Neither 'targetObject' nor 'targetBeanName' specified, and PropertyPathFactoryBean " +
@@ -205,9 +213,12 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
}
else {
// Fetch prototype target bean...
Assert.state(this.beanFactory != null, "No BeanFactory available");
Assert.state(this.targetBeanName != null, "No target bean name specified");
Object bean = this.beanFactory.getBean(this.targetBeanName);
target = PropertyAccessorFactory.forBeanPropertyAccess(bean);
}
Assert.state(this.propertyPath != null, "No property path specified");
return target.getPropertyValue(this.propertyPath);
}

View File

@@ -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 javax.inject.Provider;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -41,6 +42,7 @@ import org.springframework.util.Assert;
*/
public class ProviderCreatingFactoryBean extends AbstractFactoryBean<Provider<Object>> {
@Nullable
private String targetBeanName;
@@ -69,7 +71,10 @@ public class ProviderCreatingFactoryBean extends AbstractFactoryBean<Provider<Ob
@Override
protected Provider<Object> createInstance() {
return new TargetBeanProvider(getBeanFactory(), this.targetBeanName);
BeanFactory beanFactory = getBeanFactory();
Assert.state(beanFactory != null, "No BeanFactory available");
Assert.state(this.targetBeanName != null, "No target bean name specified");
return new TargetBeanProvider(beanFactory, this.targetBeanName);
}

View File

@@ -33,6 +33,7 @@ public class RuntimeBeanNameReference implements BeanReference {
private final String beanName;
@Nullable
private Object source;
@@ -59,6 +60,7 @@ public class RuntimeBeanNameReference implements BeanReference {
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -34,6 +34,7 @@ public class RuntimeBeanReference implements BeanReference {
private final boolean toParent;
@Nullable
private Object source;
@@ -84,6 +85,7 @@ public class RuntimeBeanReference implements BeanReference {
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -31,6 +31,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -189,14 +190,19 @@ import org.springframework.util.StringUtils;
*/
public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFactoryAware, InitializingBean {
@Nullable
private Class<?> serviceLocatorInterface;
@Nullable
private Constructor<Exception> serviceLocatorExceptionConstructor;
@Nullable
private Properties serviceMappings;
@Nullable
private ListableBeanFactory beanFactory;
@Nullable
private Object proxy;
@@ -278,15 +284,15 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
@SuppressWarnings("unchecked")
protected Constructor<Exception> determineServiceLocatorExceptionConstructor(Class<? extends Exception> exceptionClass) {
try {
return (Constructor<Exception>) exceptionClass.getConstructor(new Class<?>[] {String.class, Throwable.class});
return (Constructor<Exception>) exceptionClass.getConstructor(String.class, Throwable.class);
}
catch (NoSuchMethodException ex) {
try {
return (Constructor<Exception>) exceptionClass.getConstructor(new Class<?>[] {Throwable.class});
return (Constructor<Exception>) exceptionClass.getConstructor(Throwable.class);
}
catch (NoSuchMethodException ex2) {
try {
return (Constructor<Exception>) exceptionClass.getConstructor(new Class<?>[] {String.class});
return (Constructor<Exception>) exceptionClass.getConstructor(String.class);
}
catch (NoSuchMethodException ex3) {
throw new IllegalArgumentException(
@@ -354,7 +360,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
return System.identityHashCode(proxy);
}
else if (ReflectionUtils.isToStringMethod(method)) {
return "Service locator: " + serviceLocatorInterface.getName();
return "Service locator: " + serviceLocatorInterface;
}
else {
return invokeServiceLocatorMethod(method, args);
@@ -365,6 +371,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
Class<?> serviceLocatorMethodReturnType = getServiceLocatorMethodReturnType(method);
try {
String beanName = tryGetBeanName(args);
Assert.state(beanFactory != null, "No BeanFactory available");
if (StringUtils.hasLength(beanName)) {
// Service locator for a specific bean name
return beanFactory.getBean(beanName, serviceLocatorMethodReturnType);
@@ -401,6 +408,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
}
private Class<?> getServiceLocatorMethodReturnType(Method method) throws NoSuchMethodException {
Assert.state(serviceLocatorInterface != null, "No service locator interface specified");
Class<?>[] paramTypes = method.getParameterTypes();
Method interfaceMethod = serviceLocatorInterface.getMethod(method.getName(), paramTypes);
Class<?> serviceLocatorReturnType = interfaceMethod.getReturnType();

View File

@@ -35,9 +35,11 @@ import org.springframework.lang.Nullable;
*/
public class SetFactoryBean extends AbstractFactoryBean<Set<Object>> {
@Nullable
private Set<?> sourceSet;
@SuppressWarnings("rawtypes")
@Nullable
private Class<? extends Set> targetSetClass;

View File

@@ -37,12 +37,16 @@ import org.springframework.util.ObjectUtils;
*/
public class TypedStringValue implements BeanMetadataElement {
@Nullable
private String value;
@Nullable
private volatile Object targetType;
@Nullable
private Object source;
@Nullable
private String specifiedTypeName;
private volatile boolean dynamic;
@@ -157,7 +161,7 @@ public class TypedStringValue implements BeanMetadataElement {
* @throws ClassNotFoundException if the type cannot be resolved
*/
@Nullable
public Class<?> resolveTargetType(ClassLoader classLoader) throws ClassNotFoundException {
public Class<?> resolveTargetType(@Nullable ClassLoader classLoader) throws ClassNotFoundException {
String typeName = getTargetTypeName();
if (typeName == null) {
return null;
@@ -177,6 +181,7 @@ public class TypedStringValue implements BeanMetadataElement {
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -21,6 +21,7 @@ import java.util.Map;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
/**
* Factory for a {@code Map} that reads from a YAML source, preserving the
@@ -71,6 +72,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
private boolean singleton = true;
@Nullable
private Map<String, Object> map;

View File

@@ -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,7 @@ import java.util.Properties;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.CollectionFactory;
import org.springframework.lang.Nullable;
/**
* Factory for {@link java.util.Properties} that reads from a YAML source,
@@ -82,6 +83,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB
private boolean singleton = true;
@Nullable
private Properties properties;

View File

@@ -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.
@@ -33,6 +33,7 @@ public class AliasDefinition implements BeanMetadataElement {
private final String alias;
@Nullable
private final Object source;
@@ -75,6 +76,7 @@ public class AliasDefinition implements BeanMetadataElement {
}
@Override
@Nullable
public final Object getSource() {
return this.source;
}

View File

@@ -35,6 +35,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition {
private final String name;
@Nullable
private final Object source;
private final List<ComponentDefinition> nestedComponents = new LinkedList<>();
@@ -58,6 +59,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition {
}
@Override
@Nullable
public Object getSource() {
return this.source;
}

View File

@@ -32,8 +32,10 @@ public class ImportDefinition implements BeanMetadataElement {
private final String importedResource;
@Nullable
private final Resource[] actualResources;
@Nullable
private final Object source;
@@ -74,11 +76,13 @@ public class ImportDefinition implements BeanMetadataElement {
return this.importedResource;
}
@Nullable
public final Resource[] getActualResources() {
return this.actualResources;
}
@Override
@Nullable
public final Object getSource() {
return this.source;
}

View File

@@ -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,6 +37,7 @@ public class Location {
private final Resource resource;
@Nullable
private final Object source;

View File

@@ -36,8 +36,10 @@ public class Problem {
private final Location location;
@Nullable
private final ParseState parseState;
@Nullable
private final Throwable rootCause;

View File

@@ -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.
@@ -35,8 +35,10 @@ import org.springframework.util.ClassUtils;
public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFactoryBean<Object>
implements BeanClassLoaderAware {
@Nullable
private Class<?> serviceType;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@@ -50,6 +52,7 @@ public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFact
/**
* Return the desired service type.
*/
@Nullable
public Class<?> getServiceType() {
return this.serviceType;
}

View File

@@ -125,6 +125,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
private InstantiationStrategy instantiationStrategy = new CglibSubclassingInstantiationStrategy();
/** Resolver strategy for method parameter names */
@Nullable
private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
/** Whether to automatically try to resolve circular references between beans */
@@ -755,13 +756,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
Class<?> returnType = AutowireUtils.resolveReturnTypeForFactoryMethod(
factoryMethod, args, getBeanClassLoader());
if (returnType != null) {
uniqueCandidate = (commonType == null ? factoryMethod : null);
commonType = ClassUtils.determineCommonAncestor(returnType, commonType);
if (commonType == null) {
// Ambiguous return types found: return null to indicate "not determinable".
return null;
}
uniqueCandidate = (commonType == null ? factoryMethod : null);
commonType = ClassUtils.determineCommonAncestor(returnType, commonType);
if (commonType == null) {
// Ambiguous return types found: return null to indicate "not determinable".
return null;
}
}
catch (Throwable ex) {
@@ -869,7 +868,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
*/
@Nullable
private Class<?> getTypeForFactoryBeanFromMethod(Class<?> beanClass, final String factoryMethodName) {
class Holder { Class<?> value = null; }
class Holder { @Nullable Class<?> value = null; }
final Holder objectType = new Holder();
// CGLIB subclass methods hide generic parameters; look at the original user class.
@@ -1731,7 +1730,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
((BeanNameAware) bean).setBeanName(beanName);
}
if (bean instanceof BeanClassLoaderAware) {
((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
ClassLoader bcl = getBeanClassLoader();
if (bcl != null) {
((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);
}
}
if (bean instanceof BeanFactoryAware) {
((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);

View File

@@ -137,8 +137,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
public static final String INFER_METHOD = "(inferred)";
@Nullable
private volatile Object beanClass;
@Nullable
private String scope = SCOPE_DEFAULT;
private boolean abstractFlag = false;
@@ -149,6 +151,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private int dependencyCheck = DEPENDENCY_CHECK_NONE;
@Nullable
private String[] dependsOn;
private boolean autowireCandidate = true;
@@ -157,14 +160,17 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>(0);
@Nullable
private Supplier<?> instanceSupplier;
private boolean nonPublicAccessAllowed = true;
private boolean lenientConstructorResolution = true;
@Nullable
private String factoryBeanName;
@Nullable
private String factoryMethodName;
private ConstructorArgumentValues constructorArgumentValues;
@@ -173,8 +179,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private MethodOverrides methodOverrides = new MethodOverrides();
@Nullable
private String initMethodName;
@Nullable
private String destroyMethodName;
private boolean enforceInitMethod = true;
@@ -185,8 +193,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private int role = BeanDefinition.ROLE_APPLICATION;
@Nullable
private String description;
@Nullable
private Resource resource;
@@ -202,8 +212,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* constructor argument values and property values.
*/
protected AbstractBeanDefinition(@Nullable ConstructorArgumentValues cargs, @Nullable MutablePropertyValues pvs) {
setConstructorArgumentValues(cargs);
setPropertyValues(pvs);
this.constructorArgumentValues = (cargs != null ? cargs : new ConstructorArgumentValues());
this.propertyValues = (pvs != null ? pvs : new MutablePropertyValues());
}
/**
@@ -219,8 +229,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
setLazyInit(original.isLazyInit());
setFactoryBeanName(original.getFactoryBeanName());
setFactoryMethodName(original.getFactoryMethodName());
setConstructorArgumentValues(new ConstructorArgumentValues(original.getConstructorArgumentValues()));
setPropertyValues(new MutablePropertyValues(original.getPropertyValues()));
this.constructorArgumentValues = new ConstructorArgumentValues(original.getConstructorArgumentValues());
this.propertyValues = new MutablePropertyValues(original.getPropertyValues());
setRole(original.getRole());
setSource(original.getSource());
copyAttributesFrom(original);
@@ -399,7 +409,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @throws ClassNotFoundException if the class name could be resolved
*/
@Nullable
public Class<?> resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundException {
public Class<?> resolveBeanClass(@Nullable ClassLoader classLoader) throws ClassNotFoundException {
String className = getBeanClassName();
if (className == null) {
return null;
@@ -428,6 +438,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return the name of the target scope for the bean.
*/
@Override
@Nullable
public String getScope() {
return this.scope;
}
@@ -574,6 +585,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return the bean names that this bean depends on.
*/
@Override
@Nullable
public String[] getDependsOn() {
return this.dependsOn;
}
@@ -735,6 +747,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return the factory bean name, if any.
*/
@Override
@Nullable
public String getFactoryBeanName() {
return this.factoryBeanName;
}
@@ -756,6 +769,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return a factory method, if any.
*/
@Override
@Nullable
public String getFactoryMethodName() {
return this.factoryMethodName;
}
@@ -923,6 +937,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return a human-readable description of this bean definition.
*/
@Override
@Nullable
public String getDescription() {
return this.description;
}
@@ -931,13 +946,14 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Set the resource that this bean definition came from
* (for the purpose of showing context in case of errors).
*/
public void setResource(Resource resource) {
public void setResource(@Nullable Resource resource) {
this.resource = resource;
}
/**
* Return the resource that this bean definition came from.
*/
@Nullable
public Resource getResource() {
return this.resource;
}

View File

@@ -52,8 +52,10 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
private final BeanDefinitionRegistry registry;
@Nullable
private ResourceLoader resourceLoader;
@Nullable
private ClassLoader beanClassLoader;
private Environment environment;
@@ -120,11 +122,12 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
*/
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
@Override
@Nullable
public ResourceLoader getResourceLoader() {
return this.resourceLoader;
}
@@ -141,6 +144,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
}
@Override
@Nullable
public ClassLoader getBeanClassLoader() {
return this.beanClassLoader;
}

View File

@@ -113,21 +113,26 @@ import org.springframework.util.StringValueResolver;
public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport implements ConfigurableBeanFactory {
/** Parent bean factory, for bean inheritance support */
@Nullable
private BeanFactory parentBeanFactory;
/** ClassLoader to resolve bean class names with, if necessary */
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
/** ClassLoader to temporarily resolve bean class names with, if necessary */
@Nullable
private ClassLoader tempClassLoader;
/** Whether to cache bean metadata or rather reobtain it for every access */
private boolean cacheBeanMetadata = true;
/** Resolution strategy for expressions in bean definition values */
@Nullable
private BeanExpressionResolver beanExpressionResolver;
/** Spring ConversionService to use instead of PropertyEditors */
@Nullable
private ConversionService conversionService;
/** Custom PropertyEditorRegistrars to apply to the beans of this factory */
@@ -137,6 +142,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private final Map<Class<?>, Class<? extends PropertyEditor>> customEditors = new HashMap<>(4);
/** A custom TypeConverter to use, overriding the default PropertyEditor mechanism */
@Nullable
private TypeConverter typeConverter;
/** String resolvers to apply e.g. to annotation attribute values */
@@ -155,6 +161,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private final Map<String, Scope> scopes = new LinkedHashMap<>(8);
/** Security context used when running with a SecurityManager */
@Nullable
private SecurityContextProvider securityContextProvider;
/** Map from bean name to merged RootBeanDefinition */
@@ -681,6 +688,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
//---------------------------------------------------------------------
@Override
@Nullable
public BeanFactory getParentBeanFactory() {
return this.parentBeanFactory;
}
@@ -711,6 +719,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public ClassLoader getBeanClassLoader() {
return this.beanClassLoader;
}
@@ -721,6 +730,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public ClassLoader getTempClassLoader() {
return this.tempClassLoader;
}
@@ -741,6 +751,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public BeanExpressionResolver getBeanExpressionResolver() {
return this.beanExpressionResolver;
}
@@ -751,6 +762,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public ConversionService getConversionService() {
return this.conversionService;
}
@@ -1172,7 +1184,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
Throwable rootCause = ex.getMostSpecificCause();
if (rootCause instanceof BeanCurrentlyInCreationException) {
BeanCreationException bce = (BeanCreationException) rootCause;
if (isCurrentlyInCreation(bce.getBeanName())) {
String bceBeanName = bce.getBeanName();
if (bceBeanName != null && isCurrentlyInCreation(bceBeanName)) {
if (logger.isDebugEnabled()) {
logger.debug("PropertyEditorRegistrar [" + registrar.getClass().getName() +
"] failed because it tried to obtain currently created bean '" +

Some files were not shown because too many files have changed in this diff Show More