diff --git a/spring-aop/src/main/java/org/springframework/aop/Advisor.java b/spring-aop/src/main/java/org/springframework/aop/Advisor.java
index 8959552925..a06d9809dc 100644
--- a/spring-aop/src/main/java/org/springframework/aop/Advisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/Advisor.java
@@ -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.
diff --git a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
index b46eb19717..67f5a4dba3 100644
--- a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
@@ -1,5 +1,5 @@
/*<
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,14 +31,14 @@ import org.springframework.lang.Nullable;
* {@code TargetSources} directly: this is an AOP framework interface.
*
* @author Rod Johnson
+ * @author Juergen Hoeller
*/
public interface TargetSource extends TargetClassAware {
/**
* Return the type of targets returned by this {@link TargetSource}.
- *
Can return {@code null}, although certain usages of a
- * {@code TargetSource} might just work with a predetermined
- * target class.
+ *
Can return {@code null}, although certain usages of a {@code TargetSource}
+ * might just work with a predetermined target class.
* @return the type of targets returned by this {@link TargetSource}
*/
@Override
@@ -46,9 +46,8 @@ public interface TargetSource extends TargetClassAware {
/**
* Will all calls to {@link #getTarget()} return the same object?
- *
In that case, there will be no need to invoke
- * {@link #releaseTarget(Object)}, and the AOP framework can cache
- * the return value of {@link #getTarget()}.
+ *
In that case, there will be no need to invoke {@link #releaseTarget(Object)},
+ * and the AOP framework can cache the return value of {@link #getTarget()}.
* @return {@code true} if the target is immutable
* @see #getTarget
*/
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
index daf6f13a63..9104ea91ec 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -208,6 +208,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
/**
* Return the ClassLoader for aspect instances.
*/
+ @Nullable
public final ClassLoader getAspectClassLoader() {
return this.aspectInstanceFactory.getAspectClassLoader();
}
@@ -296,8 +297,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
catch (Throwable ex) {
throw new IllegalArgumentException("Returning name '" + name +
- "' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
- "Root cause: " + ex);
+ "' is neither a valid argument name nor the fully-qualified " +
+ "name of a Java type on the classpath. Root cause: " + ex);
}
}
}
@@ -306,6 +307,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
return this.discoveredReturningType;
}
+ @Nullable
protected Type getDiscoveredReturningGenericType() {
return this.discoveredReturningGenericType;
}
@@ -330,8 +332,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
catch (Throwable ex) {
throw new IllegalArgumentException("Throwing name '" + name +
- "' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
- "Root cause: " + ex);
+ "' is neither a valid argument name nor the fully-qualified " +
+ "name of a Java type on the classpath. Root cause: " + ex);
}
}
}
@@ -549,7 +551,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* @param ex the exception thrown by the method execution (may be null)
* @return the empty array if there are no arguments
*/
- protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) {
+ protected Object[] argBinding(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
+ @Nullable Object returnValue, @Nullable Throwable ex) {
+
calculateArgumentBindings();
// AMC start
@@ -608,13 +612,16 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* @return the invocation result
* @throws Throwable in case of invocation failure
*/
- protected Object invokeAdviceMethod(JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable {
+ protected Object invokeAdviceMethod(
+ @Nullable JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex)
+ throws Throwable {
+
return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex));
}
// As above, but in this case we are given the join point.
- protected Object invokeAdviceMethod(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t)
- throws Throwable {
+ protected Object invokeAdviceMethod(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
+ @Nullable Object returnValue, @Nullable Throwable t) throws Throwable {
return invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t));
}
@@ -649,6 +656,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
/**
* Get the current join point match at the join point we are being dispatched on.
*/
+ @Nullable
protected JoinPointMatch getJoinPointMatch() {
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
if (!(mi instanceof ProxyMethodInvocation)) {
@@ -663,8 +671,10 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
// 'last man wins' which is not what we want at all.
// Using the expression is guaranteed to be safe, since 2 identical expressions
// are guaranteed to bind in exactly the same way.
+ @Nullable
protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) {
- return (JoinPointMatch) pmi.getUserAttribute(this.pointcut.getExpression());
+ String expression = this.pointcut.getExpression();
+ return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java
index 2f1e7aaa6b..b0c2c668f3 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.aop.aspectj;
import org.springframework.core.Ordered;
+import org.springframework.lang.Nullable;
/**
* Interface implemented to provide an instance of an AspectJ aspect.
@@ -40,8 +41,10 @@ public interface AspectInstanceFactory extends Ordered {
/**
* Expose the aspect class loader that this factory uses.
- * @return the aspect class loader (never {@code null})
+ * @return the aspect class loader (or {@code null} for the bootstrap loader)
+ * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
*/
+ @Nullable
ClassLoader getAspectClassLoader();
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
index aba3617cd7..70e9a72e65 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -183,10 +183,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* Create a new discoverer that attempts to discover parameter names
* from the given pointcut expression.
*/
- public AspectJAdviceParameterNameDiscoverer(String pointcutExpression) {
+ public AspectJAdviceParameterNameDiscoverer(@Nullable String pointcutExpression) {
this.pointcutExpression = pointcutExpression;
}
+
/**
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
@@ -214,6 +215,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
this.throwingName = throwingName;
}
+
/**
* Deduce the parameter names for an advice method.
*
See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
@@ -475,8 +477,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* If the token starts meets Java identifier conventions, it's in.
*/
@Nullable
- private String maybeExtractVariableName(String candidateToken) {
- if (candidateToken == null || candidateToken.equals("")) {
+ private String maybeExtractVariableName(@Nullable String candidateToken) {
+ if (!StringUtils.hasLength(candidateToken)) {
return null;
}
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
@@ -498,7 +500,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* Given an args pointcut body (could be {@code args} or {@code at_args}),
* add any candidate variable names to the given list.
*/
- private void maybeExtractVariableNamesFromArgs(String argsSpec, List varNames) {
+ private void maybeExtractVariableNamesFromArgs(@Nullable String argsSpec, List varNames) {
if (argsSpec == null) {
return;
}
@@ -781,7 +783,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
private String text;
- public PointcutBody(int tokens, String text) {
+ public PointcutBody(int tokens, @Nullable String text) {
this.numTokensConsumed = tokens;
this.text = text;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java
index 66f3b03bf4..6e8c1f4651 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java
@@ -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.
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java
index 026c493420..784ce99e55 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,6 +57,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -196,6 +197,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
/**
* Determine the ClassLoader to use for pointcut evaluation.
*/
+ @Nullable
private ClassLoader determinePointcutClassLoader() {
if (this.beanFactory instanceof ConfigurableBeanFactory) {
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
@@ -209,21 +211,27 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
/**
* Build the underlying AspectJ pointcut expression.
*/
- private PointcutExpression buildPointcutExpression(ClassLoader classLoader) {
+ private PointcutExpression buildPointcutExpression(@Nullable ClassLoader classLoader) {
PointcutParser parser = initializePointcutParser(classLoader);
PointcutParameter[] pointcutParameters = new PointcutParameter[this.pointcutParameterNames.length];
for (int i = 0; i < pointcutParameters.length; i++) {
pointcutParameters[i] = parser.createPointcutParameter(
this.pointcutParameterNames[i], this.pointcutParameterTypes[i]);
}
- return parser.parsePointcutExpression(replaceBooleanOperators(getExpression()),
+ return parser.parsePointcutExpression(replaceBooleanOperators(resolveExpression()),
this.pointcutDeclarationScope, pointcutParameters);
}
+ private String resolveExpression() {
+ String expression = getExpression();
+ Assert.state(expression != null, "No expression set");
+ return expression;
+ }
+
/**
* Initialize the underlying AspectJ pointcut parser.
*/
- private PointcutParser initializePointcutParser(ClassLoader classLoader) {
+ private PointcutParser initializePointcutParser(@Nullable ClassLoader classLoader) {
PointcutParser parser = PointcutParser
.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(
SUPPORTED_PRIMITIVES, classLoader);
@@ -301,7 +309,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
// we say this is not a match as in Spring there will never be a different
// runtime subtype.
RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch);
- return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass));
+ return (!walker.testsSubtypeSensitiveVars() ||
+ (targetClass != null && walker.testTargetInstanceOfResidue(targetClass)));
}
}
@@ -354,7 +363,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* type but not 'this' (as would be the case of JDK dynamic proxies).
* See SPR-2979 for the original bug.
*/
- if (pmi != null) { // there is a current invocation
+ if (pmi != null && thisObject != null) { // there is a current invocation
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(originalShadowMatch);
if (!originalMethodResidueTest.testThisInstanceOfResidue(thisObject.getClass())) {
return false;
@@ -375,6 +384,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
}
+ @Nullable
protected String getCurrentProxiedBeanName() {
return ProxyCreationContext.getCurrentProxiedBeanName();
}
@@ -411,7 +421,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
// 'last man wins' which is not what we want at all.
// Using the expression is guaranteed to be safe, since 2 identical expressions
// are guaranteed to bind in exactly the same way.
- invocation.setUserAttribute(getExpression(), jpm);
+ invocation.setUserAttribute(resolveExpression(), jpm);
}
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
@@ -600,7 +610,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
return false;
}
- private FuzzyBoolean contextMatch(Class> targetType) {
+ private FuzzyBoolean contextMatch(@Nullable Class> targetType) {
String advisedBeanName = getCurrentProxiedBeanName();
if (advisedBeanName == null) { // no proxy creation in progress
// abstain; can't return YES, since that will make pointcut with negation fail
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java
index 1c89754195..e88b8fc194 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.lang.Nullable;
/**
* Spring AOP Advisor that can be used for any AspectJ pointcut expression.
@@ -37,6 +38,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
this.pointcut.setExpression(expression);
}
+ @Nullable
public String getExpression() {
return this.pointcut.getExpression();
}
@@ -45,6 +47,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
this.pointcut.setLocation(location);
}
+ @Nullable
public String getLocation() {
return this.pointcut.getLocation();
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
index 2f4b7d67bd..1bef6b684f 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -212,6 +212,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
}
+ @Nullable
private String resolveExpression(A annotation) throws Exception {
String expression = null;
for (String methodName : EXPRESSION_PROPERTIES) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java
index a6049ba271..46ba0f50ba 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJProxyFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,7 +119,9 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
*/
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
List advisors = this.aspectFactory.getAdvisors(instanceFactory);
- advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
+ Class> targetClass = getTargetClass();
+ Assert.state(targetClass != null, "Unresolvable target class");
+ advisors = AopUtils.findAdvisorsThatCanApply(advisors, targetClass);
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
AnnotationAwareOrderComparator.sort(advisors);
addAdvisors(advisors);
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java
index afb8ceb332..9539895a09 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.OrderUtils;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -58,7 +59,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
* @param name name of the bean
*/
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
- this(beanFactory, name, beanFactory.getType(name));
+ this(beanFactory, name, null);
}
/**
@@ -68,13 +69,19 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
* @param beanFactory BeanFactory to obtain instance(s) from
* @param name the name of the bean
* @param type the type that should be introspected by AspectJ
+ * ({@code null} indicates resolution through {@link BeanFactory#getType} via the bean name)
*/
- public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class> type) {
+ public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, @Nullable Class> type) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.notNull(name, "Bean name must not be null");
this.beanFactory = beanFactory;
this.name = name;
- this.aspectMetadata = new AspectMetadata(type, name);
+ Class> resolvedType = type;
+ if (type == null) {
+ resolvedType = beanFactory.getType(name);
+ Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class");
+ }
+ this.aspectMetadata = new AspectMetadata(resolvedType, name);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java
index 7b4c48098f..6a83acbafa 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,9 @@ import org.springframework.lang.Nullable;
class InstantiationModelAwarePointcutAdvisorImpl
implements InstantiationModelAwarePointcutAdvisor, AspectJPrecedenceInformation, Serializable {
+ private static Advice EMPTY_ADVICE = new Advice() {};
+
+
private final AspectJExpressionPointcut declaredPointcut;
private final Class> declaringClass;
@@ -157,9 +160,10 @@ class InstantiationModelAwarePointcutAdvisorImpl
}
- private Advice instantiateAdvice(AspectJExpressionPointcut pcut) {
- return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut,
+ private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
+ Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
+ return (advice != null ? advice : EMPTY_ADVICE);
}
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java
index 757c7369cf..fd9fdf48d3 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -132,7 +132,9 @@ class AspectJPrecedenceComparator implements Comparator {
// pre-condition is that hasAspectName returned true
private String getAspectName(Advisor anAdvisor) {
- return AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor).getAspectName();
+ AspectJPrecedenceInformation pi = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
+ Assert.state(pi != null, "Unresolvable precedence information");
+ return pi.getAspectName();
}
private int getAspectDeclarationOrder(Advisor anAdvisor) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java b/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java
index 6495f25af9..cd6a43f8f5 100644
--- a/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java
+++ b/spring-aop/src/main/java/org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -105,8 +106,8 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
@SuppressWarnings("unchecked")
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
- List list = (List)
- beanDefinition.getPropertyValues().getPropertyValue("interceptorNames").getValue();
+ List list = (List) beanDefinition.getPropertyValues().get("interceptorNames");
+ Assert.state(list != null, "Missing 'interceptorNames' property");
list.add(interceptorName);
}
@@ -115,7 +116,9 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
}
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
- return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
+ String beanClassName = interceptorDefinition.getBeanClassName();
+ return (StringUtils.hasLength(beanClassName) ?
+ StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : "");
}
/**
diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java b/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java
index 7583e51115..0d71063bd5 100644
--- a/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java
+++ b/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanReference;
import org.springframework.beans.factory.parsing.AbstractComponentDefinition;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -50,7 +51,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
}
public AdvisorComponentDefinition(
- String advisorBeanName, BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
+ String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
@@ -60,9 +61,10 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
}
- private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
+ private void unwrapDefinitions(BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
- BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue();
+ BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
+ Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");
if (pointcutDefinition != null) {
this.beanReferences = new BeanReference[] {adviceReference};
@@ -70,7 +72,8 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
this.description = buildDescription(adviceReference, pointcutDefinition);
}
else {
- BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue();
+ BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
+ Assert.state(pointcutReference != null, "Missing 'pointcut' property");
this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
this.description = buildDescription(adviceReference, pointcutReference);
@@ -78,16 +81,15 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
}
private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) {
- return new StringBuilder("Advisor ").toString();
+ return "Advisor ";
}
private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) {
- return new StringBuilder("Advisor ").toString();
+ return "Advisor ";
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java
index 40ce417d83..2020c9fa73 100644
--- a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java
+++ b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,27 +67,39 @@ public abstract class AopConfigUtils {
}
+ @Nullable
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
return registerAutoProxyCreatorIfNecessary(registry, null);
}
- public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
+ @Nullable
+ public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
+ @Nullable Object source) {
+
return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source);
}
+ @Nullable
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
return registerAspectJAutoProxyCreatorIfNecessary(registry, null);
}
- public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
+ @Nullable
+ public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
+ @Nullable Object source) {
+
return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source);
}
+ @Nullable
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
return registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry, null);
}
- public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
+ @Nullable
+ public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
+ @Nullable Object source) {
+
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
}
@@ -106,8 +118,11 @@ public abstract class AopConfigUtils {
}
@Nullable
- private static BeanDefinition registerOrEscalateApcAsRequired(Class> cls, BeanDefinitionRegistry registry, Object source) {
+ private static BeanDefinition registerOrEscalateApcAsRequired(Class> cls, BeanDefinitionRegistry registry,
+ @Nullable Object source) {
+
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
+
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
@@ -119,6 +134,7 @@ public abstract class AopConfigUtils {
}
return null;
}
+
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
beanDefinition.setSource(source);
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
@@ -131,7 +147,7 @@ public abstract class AopConfigUtils {
return APC_PRIORITY_LIST.indexOf(clazz);
}
- private static int findPriorityForClass(String className) {
+ private static int findPriorityForClass(@Nullable String className) {
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
Class> clazz = APC_PRIORITY_LIST.get(i);
if (clazz.getName().equals(className)) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java
index 8298f9e099..56b6358ccb 100644
--- a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java
+++ b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.lang.Nullable;
/**
* Utility class for handling registration of auto-proxy creators used internally
@@ -79,7 +80,7 @@ public abstract class AopNamespaceUtils {
registerComponentIfNecessary(beanDefinition, parserContext);
}
- private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
+ private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, @Nullable Element sourceElement) {
if (sourceElement != null) {
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
if (proxyTargetClass) {
@@ -92,7 +93,7 @@ public abstract class AopNamespaceUtils {
}
}
- private static void registerComponentIfNecessary(BeanDefinition beanDefinition, ParserContext parserContext) {
+ private static void registerComponentIfNecessary(@Nullable BeanDefinition beanDefinition, ParserContext parserContext) {
if (beanDefinition != null) {
BeanComponentDefinition componentDefinition =
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java b/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java
index 52007ec176..c2caea873c 100644
--- a/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java
+++ b/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.aop.config;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanReference;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
+import org.springframework.lang.Nullable;
/**
* {@link org.springframework.beans.factory.parsing.ComponentDefinition}
@@ -37,8 +38,8 @@ public class AspectComponentDefinition extends CompositeComponentDefinition {
private final BeanReference[] beanReferences;
- public AspectComponentDefinition(
- String aspectName, BeanDefinition[] beanDefinitions, BeanReference[] beanReferences, Object source) {
+ public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions,
+ @Nullable BeanReference[] beanReferences, @Nullable Object source) {
super(aspectName, source);
this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
index 59417f743c..29a932b1c6 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
}
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
if (this.proxyClassLoader == null) {
this.proxyClassLoader = classLoader;
}
@@ -170,8 +170,10 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
}
else if (!isProxyTargetClass()) {
// Rely on AOP infrastructure to tell us what interfaces to proxy.
- proxyFactory.setInterfaces(
- ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
+ Class> targetClass = targetSource.getTargetClass();
+ if (targetClass != null) {
+ proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
+ }
}
postProcessProxyFactory(proxyFactory);
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
index 77d08740d4..efa0e1e8b5 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.aop.target.SingletonTargetSource;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -137,7 +138,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
}
@Override
- public void setTargetSource(TargetSource targetSource) {
+ public void setTargetSource(@Nullable TargetSource targetSource) {
this.targetSource = (targetSource != null ? targetSource : EMPTY_TARGET_SOURCE);
}
@@ -446,7 +447,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @param advice the advice to check inclusion of
* @return whether this advice instance is included
*/
- public boolean adviceIncluded(Advice advice) {
+ public boolean adviceIncluded(@Nullable Advice advice) {
if (advice != null) {
for (Advisor advisor : this.advisors) {
if (advisor.getAdvice() == advice) {
@@ -462,7 +463,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @param adviceClass the advice class to check
* @return the count of the interceptors of this class or subclasses
*/
- public int countAdvicesOfType(Class> adviceClass) {
+ public int countAdvicesOfType(@Nullable Class> adviceClass) {
int count = 0;
if (adviceClass != null) {
for (Advisor advisor : this.advisors) {
@@ -482,7 +483,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @param targetClass the target class
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
*/
- public List getInterceptorsAndDynamicInterceptionAdvice(Method method, Class> targetClass) {
+ public List getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class> targetClass) {
MethodCacheKey cacheKey = new MethodCacheKey(method);
List cached = this.methodCache.get(cacheKey);
if (cached == null) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
index 769219f4de..f1e5f4e32e 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
@@ -134,7 +134,7 @@ class CglibAopProxy implements AopProxy, Serializable {
* @param constructorArgs the constructor argument values
* @param constructorArgTypes the constructor argument types
*/
- public void setConstructorArguments(Object[] constructorArgs, Class>[] constructorArgTypes) {
+ public void setConstructorArguments(@Nullable Object[] constructorArgs, @Nullable Class>[] constructorArgTypes) {
if (constructorArgs == null || constructorArgTypes == null) {
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
}
@@ -233,7 +233,7 @@ class CglibAopProxy implements AopProxy, Serializable {
* Checks to see whether the supplied {@code Class} has already been validated and
* validates it if not.
*/
- private void validateClassIfNecessary(Class> proxySuperClass, ClassLoader proxyClassLoader) {
+ private void validateClassIfNecessary(Class> proxySuperClass, @Nullable ClassLoader proxyClassLoader) {
if (logger.isWarnEnabled()) {
synchronized (validatedClasses) {
if (!validatedClasses.containsKey(proxySuperClass)) {
@@ -249,7 +249,7 @@ class CglibAopProxy implements AopProxy, Serializable {
* Checks for final methods on the given {@code Class}, as well as package-visible
* methods across ClassLoaders, and writes warnings to the log for each one found.
*/
- private void doValidateClass(Class> proxySuperClass, ClassLoader proxyClassLoader, Set> ifcs) {
+ private void doValidateClass(Class> proxySuperClass, @Nullable ClassLoader proxyClassLoader, Set> ifcs) {
if (proxySuperClass != Object.class) {
Method[] methods = proxySuperClass.getDeclaredMethods();
for (Method method : methods) {
@@ -374,7 +374,7 @@ class CglibAopProxy implements AopProxy, Serializable {
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
*/
@Nullable
- private static Object processReturnType(Object proxy, Object target, Method method, @Nullable Object retVal) {
+ private static Object processReturnType(Object proxy, @Nullable Object target, Method method, @Nullable Object retVal) {
// Massage return value if necessary
if (retVal != null && retVal == target &&
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
@@ -409,11 +409,12 @@ class CglibAopProxy implements AopProxy, Serializable {
private final Object target;
- public StaticUnadvisedInterceptor(Object target) {
+ public StaticUnadvisedInterceptor(@Nullable Object target) {
this.target = target;
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object retVal = methodProxy.invoke(this.target, args);
return processReturnType(proxy, this.target, method, retVal);
@@ -429,11 +430,12 @@ class CglibAopProxy implements AopProxy, Serializable {
private final Object target;
- public StaticUnadvisedExposedInterceptor(Object target) {
+ public StaticUnadvisedExposedInterceptor(@Nullable Object target) {
this.target = target;
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object oldProxy = null;
try {
@@ -462,6 +464,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object target = this.targetSource.getTarget();
try {
@@ -469,7 +472,9 @@ class CglibAopProxy implements AopProxy, Serializable {
return processReturnType(proxy, target, method, retVal);
}
finally {
- this.targetSource.releaseTarget(target);
+ if (target != null) {
+ this.targetSource.releaseTarget(target);
+ }
}
}
}
@@ -487,6 +492,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object oldProxy = null;
Object target = this.targetSource.getTarget();
@@ -497,7 +503,9 @@ class CglibAopProxy implements AopProxy, Serializable {
}
finally {
AopContext.setCurrentProxy(oldProxy);
- this.targetSource.releaseTarget(target);
+ if (target != null) {
+ this.targetSource.releaseTarget(target);
+ }
}
}
}
@@ -512,7 +520,7 @@ class CglibAopProxy implements AopProxy, Serializable {
private Object target;
- public StaticDispatcher(Object target) {
+ public StaticDispatcher(@Nullable Object target) {
this.target = target;
}
@@ -604,13 +612,16 @@ class CglibAopProxy implements AopProxy, Serializable {
private final Class> targetClass;
- public FixedChainStaticTargetInterceptor(List adviceChain, Object target, Class> targetClass) {
+ public FixedChainStaticTargetInterceptor(
+ List adviceChain, @Nullable Object target, @Nullable Class> targetClass) {
+
this.adviceChain = adviceChain;
this.target = target;
this.targetClass = targetClass;
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
this.targetClass, this.adviceChain, methodProxy);
@@ -635,6 +646,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
@Override
+ @Nullable
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object oldProxy = null;
boolean setProxyContext = false;
@@ -697,6 +709,7 @@ class CglibAopProxy implements AopProxy, Serializable {
return this.advised.hashCode();
}
+ @Nullable
protected Object getTarget() throws Exception {
return this.advised.getTargetSource().getTarget();
}
@@ -716,8 +729,9 @@ class CglibAopProxy implements AopProxy, Serializable {
private final boolean publicMethod;
- public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments,
- Class> targetClass, List interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
+ public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method,
+ Object[] arguments, @Nullable Class> targetClass,
+ List interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
this.methodProxy = methodProxy;
@@ -751,7 +765,9 @@ class CglibAopProxy implements AopProxy, Serializable {
private final int fixedInterceptorOffset;
- public ProxyCallbackFilter(AdvisedSupport advised, Map fixedInterceptorMap, int fixedInterceptorOffset) {
+ public ProxyCallbackFilter(
+ AdvisedSupport advised, Map fixedInterceptorMap, int fixedInterceptorOffset) {
+
this.advised = advised;
this.fixedInterceptorMap = fixedInterceptorMap;
this.fixedInterceptorOffset = fixedInterceptorOffset;
@@ -859,7 +875,7 @@ class CglibAopProxy implements AopProxy, Serializable {
return INVOKE_TARGET;
}
Class> returnType = method.getReturnType();
- if (returnType.isAssignableFrom(targetClass)) {
+ if (targetClass != null && returnType.isAssignableFrom(targetClass)) {
if (logger.isDebugEnabled()) {
logger.debug("Method return type is assignable from target type and " +
"may therefore return 'this' - using INVOKE_TARGET: " + method);
@@ -886,9 +902,6 @@ class CglibAopProxy implements AopProxy, Serializable {
}
ProxyCallbackFilter otherCallbackFilter = (ProxyCallbackFilter) other;
AdvisedSupport otherAdvised = otherCallbackFilter.advised;
- if (this.advised == null || otherAdvised == null) {
- return false;
- }
if (this.advised.isFrozen() != otherAdvised.isFrozen()) {
return false;
}
@@ -922,12 +935,7 @@ class CglibAopProxy implements AopProxy, Serializable {
}
private boolean equalsAdviceClasses(Advisor a, Advisor b) {
- Advice aa = a.getAdvice();
- Advice ba = b.getAdvice();
- if (aa == null || ba == null) {
- return (aa == ba);
- }
- return (aa.getClass() == ba.getClass());
+ return (a.getAdvice().getClass() == b.getAdvice().getClass());
}
private boolean equalsPointcuts(Advisor a, Advisor b) {
@@ -944,9 +952,7 @@ class CglibAopProxy implements AopProxy, Serializable {
Advisor[] advisors = this.advised.getAdvisors();
for (Advisor advisor : advisors) {
Advice advice = advisor.getAdvice();
- if (advice != null) {
- hashCode = 13 * hashCode + advice.getClass().hashCode();
- }
+ hashCode = 13 * hashCode + advice.getClass().hashCode();
}
hashCode = 13 * hashCode + (this.advised.isFrozen() ? 1 : 0);
hashCode = 13 * hashCode + (this.advised.isExposeProxy() ? 1 : 0);
@@ -966,7 +972,7 @@ class CglibAopProxy implements AopProxy, Serializable {
private final ClassLoader classLoader;
- public ClassLoaderAwareUndeclaredThrowableStrategy(ClassLoader classLoader) {
+ public ClassLoaderAwareUndeclaredThrowableStrategy(@Nullable ClassLoader classLoader) {
super(UndeclaredThrowableException.class);
this.classLoader = classLoader;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java
index 240dc3decf..92357a5231 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -152,6 +152,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
* unless a hook method throws an exception.
*/
@Override
+ @Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
MethodInvocation invocation;
Object oldProxy = null;
@@ -249,7 +250,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
* or a dynamic proxy wrapping a JdkDynamicAopProxy instance.
*/
@Override
- public boolean equals(Object other) {
+ public boolean equals(@Nullable Object other) {
if (other == this) {
return true;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java
index 6dff81c794..b1fac4c464 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -220,7 +220,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
}
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
if (!this.classLoaderConfigured) {
this.proxyClassLoader = classLoader;
}
@@ -345,8 +345,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
// Rely on AOP infrastructure to tell us what interfaces to proxy.
- copy.setInterfaces(
- ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
+ Class> targetClass = targetSource.getTargetClass();
+ if (targetClass != null) {
+ copy.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
+ }
}
copy.setFrozen(this.freezeProxy);
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java
index 3919046b7e..fbe0b04ce4 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
* {@link org.springframework.beans.factory.BeanFactory} for loading all bean classes.
* This can be overridden here for specific proxies.
*/
- public void setProxyClassLoader(ClassLoader classLoader) {
+ public void setProxyClassLoader(@Nullable ClassLoader classLoader) {
this.proxyClassLoader = classLoader;
this.classLoaderConfigured = (classLoader != null);
}
@@ -82,7 +82,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
}
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
if (!this.classLoaderConfigured) {
this.proxyClassLoader = classLoader;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java
index 917bd4a378..664786fea8 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,8 +103,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* but would complicate the code. And it would work only for static pointcuts.
*/
protected ReflectiveMethodInvocation(
- Object proxy, Object target, Method method, Object[] arguments,
- Class> targetClass, List interceptorsAndDynamicMethodMatchers) {
+ Object proxy, @Nullable Object target, Method method, Object[] arguments,
+ @Nullable Class> targetClass, List interceptorsAndDynamicMethodMatchers) {
this.proxy = proxy;
this.target = target;
@@ -152,6 +152,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
@Override
+ @Nullable
public Object proceed() throws Throwable {
// We start with an index of -1 and increment early.
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
@@ -187,6 +188,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* @return the return value of the joinpoint
* @throws Throwable if invoking the joinpoint resulted in an exception
*/
+ @Nullable
protected Object invokeJoinpoint() throws Throwable {
return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);
}
@@ -220,7 +222,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* @see java.lang.Object#clone()
*/
@Override
- public MethodInvocation invocableClone(Object... arguments) {
+ public MethodInvocation invocableClone(@Nullable Object... arguments) {
// Force initialization of the user attributes Map,
// for having a shared Map reference in the clone.
if (this.userAttributes == null) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java
index 4cadd08999..4bcd32647e 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.AfterAdvice;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -103,6 +104,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
* @param exception the exception thrown
* @return a handler for the given exception type
*/
+ @Nullable
private Method getExceptionHandler(Throwable exception) {
Class> exceptionClass = exception.getClass();
if (logger.isTraceEnabled()) {
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
index 04400dd33b..9baa00cd93 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -238,7 +238,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
}
@Override
- public Object postProcessBeforeInstantiation(Class> beanClass, String beanName) throws BeansException {
+ public Object postProcessBeforeInstantiation(Class> beanClass, @Nullable String beanName) throws BeansException {
Object cacheKey = getCacheKey(beanClass, beanName);
if (beanName == null || !this.targetSourcedBeans.contains(beanName)) {
@@ -291,7 +291,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @see #getAdvicesAndAdvisorsForBean
*/
@Override
- public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) throws BeansException {
if (bean != null) {
Object cacheKey = getCacheKey(bean.getClass(), beanName);
if (!this.earlyProxyReferences.contains(cacheKey)) {
@@ -313,7 +313,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @param beanName the bean name
* @return the cache key for the given class and name
*/
- protected Object getCacheKey(Class> beanClass, String beanName) {
+ protected Object getCacheKey(Class> beanClass, @Nullable String beanName) {
if (StringUtils.hasLength(beanName)) {
return (FactoryBean.class.isAssignableFrom(beanClass) ?
BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
@@ -330,7 +330,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @param cacheKey the cache key for metadata access
* @return a proxy wrapping the bean, or the raw bean instance as-is
*/
- protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
+ protected Object wrapIfNecessary(Object bean, @Nullable String beanName, Object cacheKey) {
if (beanName != null && this.targetSourcedBeans.contains(beanName)) {
return bean;
}
@@ -388,7 +388,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @param beanName the name of the bean
* @return whether to skip the given bean
*/
- protected boolean shouldSkip(Class> beanClass, String beanName) {
+ protected boolean shouldSkip(Class> beanClass, @Nullable String beanName) {
return false;
}
@@ -435,8 +435,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @return the AOP proxy for the bean
* @see #buildAdvisors
*/
- protected Object createProxy(
- Class> beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) {
+ protected Object createProxy(Class> beanClass, @Nullable String beanName,
+ @Nullable Object[] specificInterceptors, TargetSource targetSource) {
if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass);
@@ -479,7 +479,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @return whether the given bean should be proxied with its target class
* @see AutoProxyUtils#shouldProxyTargetClass
*/
- protected boolean shouldProxyTargetClass(Class> beanClass, String beanName) {
+ protected boolean shouldProxyTargetClass(Class> beanClass, @Nullable String beanName) {
return (this.beanFactory instanceof ConfigurableListableBeanFactory &&
AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName));
}
@@ -506,7 +506,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* specific to this bean (may be empty, but not null)
* @return the list of Advisors for the given bean
*/
- protected Advisor[] buildAdvisors(String beanName, Object[] specificInterceptors) {
+ protected Advisor[] buildAdvisors(@Nullable String beanName, @Nullable Object[] specificInterceptors) {
// Handle prototypes correctly...
Advisor[] commonInterceptors = resolveInterceptorNames();
@@ -582,7 +582,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
*/
@Nullable
- protected abstract Object[] getAdvicesAndAdvisorsForBean(
- Class> beanClass, String beanName, @Nullable TargetSource customTargetSource) throws BeansException;
+ protected abstract Object[] getAdvicesAndAdvisorsForBean(Class> beanClass,
+ @Nullable String beanName, @Nullable TargetSource customTargetSource)
+ throws BeansException;
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java
index 21e135a3f6..2cf44715ce 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AutoProxyUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ public abstract class AutoProxyUtils {
* @param beanName the name of the bean
* @return whether the given bean should be proxied with its target class
*/
- public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
+ public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
@@ -81,7 +81,7 @@ public abstract class AutoProxyUtils {
* @see org.springframework.beans.factory.BeanFactory#getType(String)
*/
@Nullable
- public static Class> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
+ public static Class> determineTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
if (beanName == null) {
return null;
}
@@ -102,7 +102,9 @@ public abstract class AutoProxyUtils {
* @param targetClass the corresponding target class
* @since 4.2.3
*/
- static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName, Class> targetClass) {
+ static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName,
+ Class> targetClass) {
+
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java
index 1bd6a6d5e1..0c1202690e 100644
--- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInvocation;
+import org.springframework.lang.Nullable;
+
/**
* Base class for monitoring interceptors, such as performance monitors.
* Provides {@code prefix} and {@code suffix} properties
@@ -50,7 +52,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
* Set the text that will get appended to the trace data.
* Default is none.
*/
- public void setPrefix(String prefix) {
+ public void setPrefix(@Nullable String prefix) {
this.prefix = (prefix != null ? prefix : "");
}
@@ -65,7 +67,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
* Set the text that will get prepended to the trace data.
*
Default is none.
*/
- public void setSuffix(String suffix) {
+ public void setSuffix(@Nullable String suffix) {
this.suffix = (suffix != null ? suffix : "");
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
index 7ad3b28b1b..2f5c6d825c 100644
--- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
+++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
@@ -87,7 +87,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
* executor has been requested via a qualifier on the async method, in which case the
* executor will be looked up at invocation time against the enclosing bean factory
*/
- public AsyncExecutionAspectSupport(Executor defaultExecutor) {
+ public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor) {
this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
}
@@ -99,7 +99,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
* executor will be looked up at invocation time against the enclosing bean factory
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
*/
- public AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
+ public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
this.defaultExecutor = defaultExecutor;
this.exceptionHandler = exceptionHandler;
}
@@ -196,7 +196,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
* @see #getExecutorQualifier(Method)
*/
@Nullable
- protected Executor findQualifiedExecutor(BeanFactory beanFactory, String qualifier) {
+ protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) {
if (beanFactory == null) {
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
" to access qualified executor '" + qualifier + "'");
@@ -217,7 +217,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
*/
@Nullable
- protected Executor getDefaultExecutor(BeanFactory beanFactory) {
+ protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
if (beanFactory != null) {
try {
// Search for TaskExecutor bean... not plain Executor since that would
diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java
index a758fd2576..e512e10328 100644
--- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.Ordered;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
+import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -73,7 +74,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
* or {@link java.util.concurrent.ExecutorService}) to delegate to;
* as of 4.2.6, a local executor for this interceptor will be built otherwise
*/
- public AsyncExecutionInterceptor(Executor defaultExecutor) {
+ public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor) {
super(defaultExecutor);
}
@@ -84,7 +85,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
* as of 4.2.6, a local executor for this interceptor will be built otherwise
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
*/
- public AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
+ public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
super(defaultExecutor, exceptionHandler);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java
index c3e40f3540..c49d2ec4a0 100644
--- a/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -292,7 +292,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
* at {@code TRACE} level. Sub-classes can override this method
* to control which level the message is written at.
*/
- protected void writeToLog(Log logger, String message, Throwable ex) {
+ protected void writeToLog(Log logger, String message, @Nullable Throwable ex) {
if (ex != null) {
logger.trace(message, ex);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java
index f6213a7d3c..c39f5c5675 100644
--- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java
+++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.lang.Nullable;
/**
* Utility class for creating a scoped proxy.
@@ -102,7 +103,7 @@ public abstract class ScopedProxyUtils {
* bean within a scoped proxy.
* @since 4.1.4
*/
- public static boolean isScopedTarget(String beanName) {
+ public static boolean isScopedTarget(@Nullable String beanName) {
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java
index 35f4e7362f..bb8fa93b0e 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractBeanFactoryPointcutAdvisor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -101,11 +101,13 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
@Override
public Advice getAdvice() {
Advice advice = this.advice;
- if (advice != null || this.adviceBeanName == null) {
+ if (advice != null) {
return advice;
}
+ Assert.state(this.adviceBeanName != null, "'adviceBeanName' must be specified");
Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'");
+
if (this.beanFactory.isSingleton(this.adviceBeanName)) {
// Rely on singleton semantics provided by the factory.
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java
index 69178a4ac0..59ed97481a 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -127,7 +127,10 @@ public abstract class AopUtils {
* @since 4.3
* @see MethodIntrospector#selectInvocableMethod(Method, Class)
*/
- public static Method selectInvocableMethod(Method method, Class> targetType) {
+ public static Method selectInvocableMethod(Method method, @Nullable Class> targetType) {
+ if (targetType == null) {
+ return method;
+ }
Method methodToUse = MethodIntrospector.selectInvocableMethod(method, targetType);
if (Modifier.isPrivate(methodToUse.getModifiers()) && !Modifier.isStatic(methodToUse.getModifiers()) &&
SpringProxy.class.isAssignableFrom(targetType)) {
@@ -143,7 +146,7 @@ public abstract class AopUtils {
* Determine whether the given method is an "equals" method.
* @see java.lang.Object#equals
*/
- public static boolean isEqualsMethod(Method method) {
+ public static boolean isEqualsMethod(@Nullable Method method) {
return ReflectionUtils.isEqualsMethod(method);
}
@@ -151,7 +154,7 @@ public abstract class AopUtils {
* Determine whether the given method is a "hashCode" method.
* @see java.lang.Object#hashCode
*/
- public static boolean isHashCodeMethod(Method method) {
+ public static boolean isHashCodeMethod(@Nullable Method method) {
return ReflectionUtils.isHashCodeMethod(method);
}
@@ -159,7 +162,7 @@ public abstract class AopUtils {
* Determine whether the given method is a "toString" method.
* @see java.lang.Object#toString()
*/
- public static boolean isToStringMethod(Method method) {
+ public static boolean isToStringMethod(@Nullable Method method) {
return ReflectionUtils.isToStringMethod(method);
}
@@ -167,7 +170,7 @@ public abstract class AopUtils {
* Determine whether the given method is a "finalize" method.
* @see java.lang.Object#finalize()
*/
- public static boolean isFinalizeMethod(Method method) {
+ public static boolean isFinalizeMethod(@Nullable Method method) {
return (method != null && method.getName().equals("finalize") &&
method.getParameterCount() == 0);
}
@@ -326,7 +329,7 @@ public abstract class AopUtils {
* @throws org.springframework.aop.AopInvocationException in case of a reflection error
*/
@Nullable
- public static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args)
+ public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args)
throws Throwable {
// Use reflection to invoke the method.
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java
index bcfef02343..49c9808318 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.aop.support;
import org.springframework.aop.Pointcut;
+import org.springframework.lang.Nullable;
/**
* Concrete BeanFactory-based PointcutAdvisor that allows for any Advice
@@ -43,7 +44,7 @@ public class DefaultBeanFactoryPointcutAdvisor extends AbstractBeanFactoryPointc
*
Default is {@code Pointcut.TRUE}.
* @see #setAdviceBeanName
*/
- public void setPointcut(Pointcut pointcut) {
+ public void setPointcut(@Nullable Pointcut pointcut) {
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java
index 7dabc1a006..10bf83719d 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.io.Serializable;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
+import org.springframework.lang.Nullable;
/**
* Convenient Pointcut-driven Advisor implementation.
@@ -73,7 +74,7 @@ public class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor imple
*
Default is {@code Pointcut.TRUE}.
* @see #setAdvice
*/
- public void setPointcut(Pointcut pointcut) {
+ public void setPointcut(@Nullable Pointcut pointcut) {
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java
index 24077191a5..35dd9ada97 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.aop.support;
import org.springframework.aop.Pointcut;
+import org.springframework.lang.Nullable;
/**
* Interface to be implemented by pointcuts that use String expressions.
@@ -29,6 +30,7 @@ public interface ExpressionPointcut extends Pointcut {
/**
* Return the String expression for this pointcut.
*/
+ @Nullable
String getExpression();
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java
index 01672395bb..dae5b46a83 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,11 +125,11 @@ public abstract class MethodMatchers {
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
}
- protected boolean matchesClass1(Class> targetClass) {
+ protected boolean matchesClass1(@Nullable Class> targetClass) {
return true;
}
- protected boolean matchesClass2(Class> targetClass) {
+ protected boolean matchesClass2(@Nullable Class> targetClass) {
return true;
}
@@ -183,13 +183,13 @@ public abstract class MethodMatchers {
}
@Override
- protected boolean matchesClass1(Class> targetClass) {
- return this.cf1.matches(targetClass);
+ protected boolean matchesClass1(@Nullable Class> targetClass) {
+ return (targetClass != null && this.cf1.matches(targetClass));
}
@Override
- protected boolean matchesClass2(Class> targetClass) {
- return this.cf2.matches(targetClass);
+ protected boolean matchesClass2(@Nullable Class> targetClass) {
+ return (targetClass != null && this.cf2.matches(targetClass));
}
@Override
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
index 7ac7f17480..1d807d9c20 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
* Matching will be the union of all these; if any match,
* the pointcut matches.
*/
- public void setMappedNames(String... mappedNames) {
+ public void setMappedNames(@Nullable String... mappedNames) {
this.mappedNames = new LinkedList<>();
if (mappedNames != null) {
this.mappedNames.addAll(Arrays.asList(mappedNames));
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java
index 0fab429471..a5bb6d46f7 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/RegexpMethodPointcutAdvisor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.io.Serializable;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
-import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -133,7 +132,6 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
* will be used.
* @return the Pointcut instance (never {@code null})
*/
- @Nullable
protected AbstractRegexpMethodPointcut createPointcut() {
return new JdkRegexpMethodPointcut();
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
index 156e30e34f..5b69ffda00 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
@@ -69,8 +69,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
* @param methodAnnotationType the annotation type to look for at the method level
* (can be {@code null})
*/
- public AnnotationMatchingPointcut(
- @Nullable Class extends Annotation> classAnnotationType, @Nullable Class extends Annotation> methodAnnotationType) {
+ public AnnotationMatchingPointcut(@Nullable Class extends Annotation> classAnnotationType,
+ @Nullable Class extends Annotation> methodAnnotationType) {
this(classAnnotationType, methodAnnotationType, false);
}
@@ -87,8 +87,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
* @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
*/
- public AnnotationMatchingPointcut(Class extends Annotation> classAnnotationType,
- Class extends Annotation> methodAnnotationType, boolean checkInherited) {
+ public AnnotationMatchingPointcut(@Nullable Class extends Annotation> classAnnotationType,
+ @Nullable Class extends Annotation> methodAnnotationType, boolean checkInherited) {
Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
"Either Class annotation type or Method annotation type needs to be specified (or both)");
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
index 3d0e9ae4f5..3b1b9c8d65 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.aop.TargetSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
@@ -129,9 +130,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
logger.trace("Getting bean with name '" + this.targetBeanName + "' in order to determine type");
}
Object beanInstance = this.beanFactory.getBean(this.targetBeanName);
- if (beanInstance != null) {
- this.targetClass = beanInstance.getClass();
- }
+ this.targetClass = beanInstance.getClass();
}
}
return this.targetClass;
diff --git a/spring-aspects/src/test/resources/org/springframework/cache/config/annotation-cache-aspectj.xml b/spring-aspects/src/test/resources/org/springframework/cache/config/annotation-cache-aspectj.xml
index b551b66656..7887486089 100644
--- a/spring-aspects/src/test/resources/org/springframework/cache/config/annotation-cache-aspectj.xml
+++ b/spring-aspects/src/test/resources/org/springframework/cache/config/annotation-cache-aspectj.xml
@@ -22,7 +22,7 @@
-
+
@@ -40,7 +40,7 @@
-
+
@@ -55,6 +55,7 @@
+
diff --git a/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java b/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java
index 94c54fa429..39598b184b 100644
--- a/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java
+++ b/spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java
@@ -257,7 +257,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
int countBefore = getRegistry().getBeanDefinitionCount();
try {
- GroovyShell shell = new GroovyShell(getResourceLoader().getClassLoader(), binding);
+ GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
shell.evaluate(encodedResource.getReader(), "beans");
}
catch (Throwable ex) {
diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java
index a16e0a9ba9..8c7558b670 100644
--- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,10 +56,10 @@ import org.springframework.util.StringUtils;
* as String arrays are converted in such a format if the array itself is not
* assignable.
*
- * @author Rod Johnson
* @author Juergen Hoeller
- * @author Rob Harrop
* @author Stephane Nicoll
+ * @author Rod Johnson
+ * @author Rob Harrop
* @since 4.2
* @see #registerCustomEditor
* @see #setPropertyValues
@@ -189,7 +189,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @param nestedPath the nested path of the object
* @param rootObject the root object at the top of the path
*/
- public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
+ public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
this.wrappedObject = ObjectUtils.unwrapOptional(object);
Assert.notNull(this.wrappedObject, "Target object must not be null");
this.nestedPath = (nestedPath != null ? nestedPath : "");
@@ -199,11 +199,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
public final Object getWrappedInstance() {
+ Assert.state(this.wrappedObject != null, "No wrapped instance");
return this.wrappedObject;
}
public final Class> getWrappedClass() {
- return (this.wrappedObject != null ? this.wrappedObject.getClass() : null);
+ return getWrappedInstance().getClass();
}
/**
@@ -217,6 +218,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* Return the root object at the top of the path of this accessor.
* @see #getNestedPath
*/
+ @Nullable
public final Object getRootInstance() {
return this.rootObject;
}
@@ -226,11 +228,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @see #getNestedPath
*/
public final Class> getRootClass() {
- return (this.rootObject != null ? this.rootObject.getClass() : null);
+ Assert.state(this.wrappedObject != null, "No root object");
+ return this.rootObject.getClass();
}
@Override
- public void setPropertyValue(String propertyName, Object value) throws BeansException {
+ public void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException {
AbstractNestablePropertyAccessor nestedPa;
try {
nestedPa = getPropertyAccessorForPropertyPath(propertyName);
@@ -279,10 +282,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
@SuppressWarnings("unchecked")
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
Object propValue = getPropertyHoldingValue(tokens);
+ PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
+ if (ph == null) {
+ throw new InvalidPropertyException(
+ getRootClass(), this.nestedPath + tokens.actualName, "No property handler found");
+ }
String lastKey = tokens.keys[tokens.keys.length - 1];
if (propValue.getClass().isArray()) {
- PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
Class> requiredType = propValue.getClass().getComponentType();
int arrayIndex = Integer.parseInt(lastKey);
Object oldValue = null;
@@ -309,7 +316,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
else if (propValue instanceof List) {
- PropertyHandler ph = getPropertyHandler(tokens.actualName);
Class> requiredType = ph.getCollectionType(tokens.keys.length);
List list = (List) propValue;
int index = Integer.parseInt(lastKey);
@@ -346,7 +352,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
else if (propValue instanceof Map) {
- PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
Class> mapKeyType = ph.getMapKeyType(tokens.keys.length);
Class> mapValueType = ph.getMapValueType(tokens.keys.length);
Map map = (Map) propValue;
@@ -449,7 +454,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
}
- ph.setValue(this.wrappedObject, valueToApply);
+ ph.setValue(valueToApply);
}
catch (TypeMismatchException ex) {
throw ex;
@@ -567,34 +572,29 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return false;
}
- private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, Class> requiredType,
- TypeDescriptor td) throws TypeMismatchException {
+ @Nullable
+ private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
+ @Nullable Object newValue, @Nullable Class> requiredType, @Nullable TypeDescriptor td)
+ throws TypeMismatchException {
+
try {
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
}
- catch (ConverterNotFoundException ex) {
- PropertyChangeEvent pce =
- new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
- throw new ConversionNotSupportedException(pce, td.getType(), ex);
- }
- catch (ConversionException ex) {
- PropertyChangeEvent pce =
- new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
- throw new TypeMismatchException(pce, requiredType, ex);
- }
- catch (IllegalStateException ex) {
+ catch (ConverterNotFoundException | IllegalStateException ex) {
PropertyChangeEvent pce =
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
throw new ConversionNotSupportedException(pce, requiredType, ex);
}
- catch (IllegalArgumentException ex) {
+ catch (ConversionException | IllegalArgumentException ex) {
PropertyChangeEvent pce =
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
throw new TypeMismatchException(pce, requiredType, ex);
}
}
- protected Object convertForProperty(String propertyName, @Nullable Object oldValue, Object newValue, TypeDescriptor td)
+ @Nullable
+ protected Object convertForProperty(
+ String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td)
throws TypeMismatchException {
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
@@ -608,6 +608,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@SuppressWarnings("unchecked")
+ @Nullable
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalName;
String actualName = tokens.actualName;
@@ -724,10 +725,10 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
/**
- * Return a {@link PropertyHandler} for the specified local {@code propertyName}. Only
- * used to reach a property available in the current context.
+ * Return a {@link PropertyHandler} for the specified local {@code propertyName}.
+ * Only used to reach a property available in the current context.
* @param propertyName the name of a local property
- * @return the handler for that property or {@code null} if it has not been found
+ * @return the handler for that property, or {@code null} if it has not been found
*/
@Nullable
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
@@ -760,7 +761,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
Array.set(newArray, i, newValue(componentType, null, name));
}
setPropertyValue(name, newArray);
- return getPropertyValue(name);
+ Object defaultValue = getPropertyValue(name);
+ Assert.state(defaultValue != null, "Default value must not be null");
+ return defaultValue;
}
else {
return array;
@@ -872,17 +875,18 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
private Object setDefaultValue(PropertyTokenHolder tokens) {
PropertyValue pv = createDefaultPropertyValue(tokens);
setPropertyValue(tokens, pv);
- return getPropertyValue(tokens);
+ Object defaultValue = getPropertyValue(tokens);
+ Assert.state(defaultValue != null, "Default value must not be null");
+ return defaultValue;
}
private PropertyValue createDefaultPropertyValue(PropertyTokenHolder tokens) {
TypeDescriptor desc = getPropertyTypeDescriptor(tokens.canonicalName);
- Class> type = desc.getType();
- if (type == null) {
+ if (desc == null) {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
"Could not determine property type for auto-growing a default value");
}
- Object defaultValue = newValue(type, desc, tokens.canonicalName);
+ Object defaultValue = newValue(desc.getType(), desc, tokens.canonicalName);
return new PropertyValue(tokens.canonicalName, defaultValue);
}
@@ -1005,24 +1009,28 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
public abstract ResolvableType getResolvableType();
+ @Nullable
public Class> getMapKeyType(int nestingLevel) {
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(0);
}
+ @Nullable
public Class> getMapValueType(int nestingLevel) {
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(1);
}
+ @Nullable
public Class> getCollectionType(int nestingLevel) {
return getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric();
}
+ @Nullable
public abstract TypeDescriptor nested(int level);
@Nullable
public abstract Object getValue() throws Exception;
- public abstract void setValue(Object object, Object value) throws Exception;
+ public abstract void setValue(@Nullable Object value) throws Exception;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java
index ed0351decf..eb551fbd66 100644
--- a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import org.springframework.lang.Nullable;
+
/**
* Abstract implementation of the {@link PropertyAccessor} interface.
* Provides base implementations of all convenience methods, with the
@@ -151,6 +153,6 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
* accessor method failed or a type mismatch occurred
*/
@Override
- public abstract void setPropertyValue(String propertyName, Object value) throws BeansException;
+ public abstract void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java b/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java
index 976230f9df..d4f9b7d3bf 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class BeanInstantiationException extends FatalBeanException {
* @param msg the detail message
* @param cause the root cause
*/
- public BeanInstantiationException(Class> beanClass, String msg, Throwable cause) {
+ public BeanInstantiationException(Class> beanClass, String msg, @Nullable Throwable cause) {
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
this.beanClass = beanClass;
}
@@ -65,7 +65,7 @@ public class BeanInstantiationException extends FatalBeanException {
* @param cause the root cause
* @since 4.3
*/
- public BeanInstantiationException(Constructor> constructor, String msg, Throwable cause) {
+ public BeanInstantiationException(Constructor> constructor, String msg, @Nullable Throwable cause) {
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
this.beanClass = constructor.getDeclaringClass();
this.constructor = constructor;
@@ -79,7 +79,7 @@ public class BeanInstantiationException extends FatalBeanException {
* @param cause the root cause
* @since 4.3
*/
- public BeanInstantiationException(Method constructingMethod, String msg, Throwable cause) {
+ public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
this.beanClass = constructingMethod.getReturnType();
this.constructingMethod = constructingMethod;
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java
index 366256452c..e91736e8f2 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.beans;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -40,7 +41,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
* @param name the name of the attribute (never {@code null})
* @param value the value of the attribute (possibly before type conversion)
*/
- public BeanMetadataAttribute(String name, Object value) {
+ public BeanMetadataAttribute(String name, @Nullable Object value) {
Assert.notNull(name, "Name must not be null");
this.name = name;
this.value = value;
@@ -65,7 +66,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java
index 175338f1e9..924474bd08 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java
@@ -37,7 +37,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
* Set the configuration source {@code Object} for this metadata element.
*
The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
index 70c7840e15..7a5f9c5234 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -426,7 +426,7 @@ public abstract class BeanUtils {
* @return the corresponding editor, or {@code null} if none found
*/
@Nullable
- public static PropertyEditor findEditorByConvention(Class> targetType) {
+ public static PropertyEditor findEditorByConvention(@Nullable Class> targetType) {
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
return null;
}
@@ -476,7 +476,7 @@ public abstract class BeanUtils {
* @param beanClasses the classes to check against
* @return the property type, or {@code Object.class} as fallback
*/
- public static Class> findPropertyType(String propertyName, Class>... beanClasses) {
+ public static Class> findPropertyType(String propertyName, @Nullable Class>... beanClasses) {
if (beanClasses != null) {
for (Class> beanClass : beanClasses) {
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
@@ -599,8 +599,8 @@ public abstract class BeanUtils {
* @throws BeansException if the copying failed
* @see BeanWrapper
*/
- private static void copyProperties(Object source, Object target, @Nullable Class> editable, String... ignoreProperties)
- throws BeansException {
+ private static void copyProperties(Object source, Object target, @Nullable Class> editable,
+ @Nullable String... ignoreProperties) throws BeansException {
Assert.notNull(source, "Source must not be null");
Assert.notNull(target, "Target must not be null");
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java b/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java
index 1aa32d3733..cebe378152 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@ package org.springframework.beans;
import java.beans.PropertyDescriptor;
-import org.springframework.lang.Nullable;
-
/**
* The central interface of Spring's low-level JavaBeans infrastructure.
*
@@ -64,18 +62,13 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
int getAutoGrowCollectionLimit();
/**
- * Return the bean instance wrapped by this object, if any.
- * @return the bean instance, or {@code null} if none set
+ * Return the bean instance wrapped by this object.
*/
- @Nullable
Object getWrappedInstance();
/**
- * Return the type of the wrapped JavaBean object.
- * @return the type of the wrapped bean instance,
- * or {@code null} if no wrapped object has been set
+ * Return the type of the wrapped bean instance.
*/
- @Nullable
Class> getWrappedClass();
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
index f69b08c946..6a48196ce4 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.beans;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -29,7 +28,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.convert.Property;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
-import org.springframework.util.Assert;
+import org.springframework.util.ReflectionUtils;
/**
* Default {@link BeanWrapper} implementation that should be sufficient
@@ -148,7 +147,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
- public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
+ public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
super.setWrappedInstance(object, nestedPath, rootObject);
setIntrospectionClass(getWrappedClass());
}
@@ -169,7 +168,6 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* for the wrapped object.
*/
private CachedIntrospectionResults getCachedIntrospectionResults() {
- Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
if (this.cachedIntrospectionResults == null) {
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
}
@@ -203,6 +201,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* @return the new value, possibly the result of type conversion
* @throws TypeMismatchException if type conversion failed
*/
+ @Nullable
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
@@ -289,73 +288,45 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
@Override
public Object getValue() throws Exception {
final Method readMethod = this.pd.getReadMethod();
- if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) {
- if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- readMethod.setAccessible(true);
- return null;
- }
- });
- }
- else {
- readMethod.setAccessible(true);
- }
- }
if (System.getSecurityManager() != null) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(readMethod);
+ return null;
+ });
try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- return readMethod.invoke(getWrappedInstance(), (Object[]) null);
- }
- }, acc);
+ return AccessController.doPrivileged((PrivilegedExceptionAction) () ->
+ readMethod.invoke(getWrappedInstance(), (Object[]) null), acc);
}
catch (PrivilegedActionException pae) {
throw pae.getException();
}
}
else {
+ ReflectionUtils.makeAccessible(readMethod);
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
}
}
@Override
- public void setValue(final Object object, Object valueToApply) throws Exception {
+ public void setValue(final @Nullable Object value) throws Exception {
final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?
((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :
this.pd.getWriteMethod());
- if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers()) && !writeMethod.isAccessible()) {
- if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- writeMethod.setAccessible(true);
- return null;
- }
- });
- }
- else {
- writeMethod.setAccessible(true);
- }
- }
- final Object value = valueToApply;
if (System.getSecurityManager() != null) {
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(writeMethod);
+ return null;
+ });
try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- writeMethod.invoke(object, value);
- return null;
- }
- }, acc);
+ AccessController.doPrivileged((PrivilegedExceptionAction) () ->
+ writeMethod.invoke(getWrappedInstance(), value), acc);
}
catch (PrivilegedActionException ex) {
throw ex.getException();
}
}
else {
+ ReflectionUtils.makeAccessible(writeMethod);
writeMethod.invoke(getWrappedInstance(), value);
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/BeansException.java b/spring-beans/src/main/java/org/springframework/beans/BeansException.java
index efbed41edf..0603da9489 100644
--- a/spring-beans/src/main/java/org/springframework/beans/BeansException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/BeansException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
package org.springframework.beans;
import org.springframework.core.NestedRuntimeException;
-import org.springframework.util.ObjectUtils;
+import org.springframework.lang.Nullable;
/**
* Abstract superclass for all exceptions thrown in the beans package
@@ -46,27 +46,8 @@ public abstract class BeansException extends NestedRuntimeException {
* @param msg the detail message
* @param cause the root cause
*/
- public BeansException(String msg, Throwable cause) {
+ public BeansException(@Nullable String msg, @Nullable Throwable cause) {
super(msg, cause);
}
-
- @Override
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (!(other instanceof BeansException)) {
- return false;
- }
- BeansException otherBe = (BeansException) other;
- return (getMessage().equals(otherBe.getMessage()) &&
- ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause()));
- }
-
- @Override
- public int hashCode() {
- return getMessage().hashCode();
- }
-
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
index cbff644296..07ca078212 100644
--- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
+++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.SpringProperties;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.io.support.SpringFactoriesLoader;
+import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.StringUtils;
@@ -136,7 +137,7 @@ public class CachedIntrospectionResults {
* be paired with a {@link #clearClassLoader} call at application shutdown.
* @param classLoader the ClassLoader to accept
*/
- public static void acceptClassLoader(ClassLoader classLoader) {
+ public static void acceptClassLoader(@Nullable ClassLoader classLoader) {
if (classLoader != null) {
acceptedClassLoaders.add(classLoader);
}
@@ -148,7 +149,7 @@ public class CachedIntrospectionResults {
* removing the ClassLoader (and its children) from the acceptance list.
* @param classLoader the ClassLoader to clear the cache for
*/
- public static void clearClassLoader(ClassLoader classLoader) {
+ public static void clearClassLoader(@Nullable ClassLoader classLoader) {
for (Iterator it = acceptedClassLoaders.iterator(); it.hasNext();) {
ClassLoader registeredLoader = it.next();
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
@@ -226,7 +227,7 @@ public class CachedIntrospectionResults {
* @param candidate the candidate ClassLoader to check
* @param parent the parent ClassLoader to check for
*/
- private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
+ private static boolean isUnderneathClassLoader(@Nullable ClassLoader candidate, @Nullable ClassLoader parent) {
if (candidate == parent) {
return true;
}
@@ -336,6 +337,7 @@ public class CachedIntrospectionResults {
return this.beanInfo.getBeanDescriptor().getBeanClass();
}
+ @Nullable
PropertyDescriptor getPropertyDescriptor(String name) {
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
if (pd == null && StringUtils.hasLength(name)) {
@@ -375,6 +377,7 @@ public class CachedIntrospectionResults {
return (existing != null ? existing : td);
}
+ @Nullable
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {
return this.typeDescriptorCache.get(pd);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java
index 77fb0ee6d2..1475d4d5e8 100644
--- a/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property
* Specify a Spring 3.0 ConversionService to use for converting
* property values, as an alternative to JavaBeans PropertyEditors.
*/
- void setConversionService(ConversionService conversionService);
+ void setConversionService(@Nullable ConversionService conversionService);
/**
* Return the associated ConversionService, if any.
diff --git a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java
index 0c98a343ea..fe2c1863e4 100644
--- a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,10 +134,10 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
}
@Override
- public void setValue(Object object, Object value) throws Exception {
+ public void setValue(Object value) throws Exception {
try {
ReflectionUtils.makeAccessible(this.field);
- this.field.set(object, value);
+ this.field.set(getWrappedInstance(), value);
}
catch (IllegalAccessException ex) {
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
diff --git a/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java b/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java
index 84fe47bb23..2b7300f05c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.beans;
+import org.springframework.lang.Nullable;
+
/**
* Thrown on an unrecoverable problem encountered in the
* beans packages or sub-packages, e.g. bad class or field.
@@ -39,7 +41,7 @@ public class FatalBeanException extends BeansException {
* @param msg the detail message
* @param cause the root cause
*/
- public FatalBeanException(String msg, Throwable cause) {
+ public FatalBeanException(String msg, @Nullable Throwable cause) {
super(msg, cause);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java
index 2ef6ab67da..21f3f79858 100644
--- a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.MethodParameter;
+import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -57,18 +58,14 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
public GenericTypeAwarePropertyDescriptor(Class> beanClass, String propertyName,
- Method readMethod, Method writeMethod, Class> propertyEditorClass)
+ @Nullable Method readMethod, @Nullable Method writeMethod, Class> propertyEditorClass)
throws IntrospectionException {
super(propertyName, null, null);
-
- if (beanClass == null) {
- throw new IntrospectionException("Bean class must not be null");
- }
this.beanClass = beanClass;
- Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
- Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
+ Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
+ Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
if (writeMethodToUse == null && readMethodToUse != null) {
// Fallback: Original JavaBeans introspection might not have found matching setter
// method due to lack of bridge method resolution, in case of the getter using a
diff --git a/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java b/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java
index d451ad41a1..8cb1214130 100644
--- a/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.beans;
+import org.springframework.lang.Nullable;
+
/**
* Exception thrown when referring to an invalid bean property.
* Carries the offending bean class and property name.
@@ -48,7 +50,7 @@ public class InvalidPropertyException extends FatalBeanException {
* @param msg the detail message
* @param cause the root cause
*/
- public InvalidPropertyException(Class> beanClass, String propertyName, String msg, Throwable cause) {
+ public InvalidPropertyException(Class> beanClass, String propertyName, String msg, @Nullable Throwable cause) {
super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
this.beanClass = beanClass;
this.propertyName = propertyName;
diff --git a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java
index 8adc4e9d0b..6d084e2384 100644
--- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java
+++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* @param original the PropertyValues to copy
* @see #addPropertyValues(PropertyValues)
*/
- public MutablePropertyValues(PropertyValues original) {
+ public MutablePropertyValues(@Nullable PropertyValues original) {
// We can optimize this because it's all new:
// There is no replacement of existing property values.
if (original != null) {
@@ -82,7 +82,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* @param original Map with property values keyed by property name Strings
* @see #addPropertyValues(Map)
*/
- public MutablePropertyValues(Map, ?> original) {
+ public MutablePropertyValues(@Nullable Map, ?> original) {
// We can optimize this because it's all new:
// There is no replacement of existing property values.
if (original != null) {
@@ -103,7 +103,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* It is not intended for typical programmatic use.
* @param propertyValueList List of PropertyValue objects
*/
- public MutablePropertyValues(List propertyValueList) {
+ public MutablePropertyValues(@Nullable List propertyValueList) {
this.propertyValueList =
(propertyValueList != null ? propertyValueList : new ArrayList<>());
}
@@ -133,7 +133,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* @param other the PropertyValues to copy
* @return this in order to allow for adding multiple property values in a chain
*/
- public MutablePropertyValues addPropertyValues(PropertyValues other) {
+ public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {
if (other != null) {
PropertyValue[] pvs = other.getPropertyValues();
for (PropertyValue pv : pvs) {
@@ -149,7 +149,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* which must be a String
* @return this in order to allow for adding multiple property values in a chain
*/
- public MutablePropertyValues addPropertyValues(Map, ?> other) {
+ public MutablePropertyValues addPropertyValues(@Nullable Map, ?> other) {
if (other != null) {
for (Map.Entry, ?> entry : other.entrySet()) {
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
@@ -197,7 +197,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* @param propertyValue value of the property
* @return this in order to allow for adding multiple property values in a chain
*/
- public MutablePropertyValues add(String propertyName, Object propertyValue) {
+ public MutablePropertyValues add(String propertyName, @Nullable Object propertyValue) {
addPropertyValue(new PropertyValue(propertyName, propertyValue));
return this;
}
@@ -263,7 +263,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
/**
* Get the raw property value, if any.
* @param propertyName the name to search for
- * @return the raw property value, or {@code null}
+ * @return the raw property value, or {@code null} if none found
* @since 4.0
* @see #getPropertyValue(String)
* @see PropertyValue#getValue()
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java
index 1bb6c4ff31..32b429590a 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java
@@ -39,7 +39,7 @@ public abstract class PropertyAccessException extends BeansException {
* @param msg the detail message
* @param cause the root cause
*/
- public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, Throwable cause) {
+ public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, @Nullable Throwable cause) {
super(msg, cause);
this.propertyChangeEvent = propertyChangeEvent;
}
@@ -49,7 +49,7 @@ public abstract class PropertyAccessException extends BeansException {
* @param msg the detail message
* @param cause the root cause
*/
- public PropertyAccessException(String msg, Throwable cause) {
+ public PropertyAccessException(String msg, @Nullable Throwable cause) {
super(msg, cause);
}
@@ -67,6 +67,7 @@ public abstract class PropertyAccessException extends BeansException {
/**
* Return the name of the affected property, if available.
*/
+ @Nullable
public String getPropertyName() {
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
index 2693b7c781..960118126c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,8 +82,6 @@ public interface PropertyAccessor {
* (may be a nested path and/or an indexed/mapped property)
* @return the property type for the particular property,
* or {@code null} if not determinable
- * @throws InvalidPropertyException if there is no such property or
- * if the property isn't readable
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
@@ -97,8 +95,8 @@ public interface PropertyAccessor {
* (may be a nested path and/or an indexed/mapped property)
* @return the property type for the particular property,
* or {@code null} if not determinable
- * @throws InvalidPropertyException if there is no such property or
- * if the property isn't readable
+ * @throws PropertyAccessException if the property was valid but the
+ * accessor method failed
*/
@Nullable
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
@@ -113,6 +111,7 @@ public interface PropertyAccessor {
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
+ @Nullable
Object getPropertyValue(String propertyName) throws BeansException;
/**
@@ -125,7 +124,7 @@ public interface PropertyAccessor {
* @throws PropertyAccessException if the property was valid but the
* accessor method failed or a type mismatch occurred
*/
- void setPropertyValue(String propertyName, Object value) throws BeansException;
+ void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
/**
* Set the specified value as current property value.
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java
index 9da1ed0658..9216234aa2 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.beans;
+import org.springframework.lang.Nullable;
+
/**
* Utility methods for classes that perform bean property access
* according to the {@link PropertyAccessor} interface.
@@ -42,7 +44,7 @@ public abstract class PropertyAccessorUtils {
* @param propertyPath the property path to check
* @return whether the path indicates an indexed or nested property
*/
- public static boolean isNestedOrIndexedProperty(String propertyPath) {
+ public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath) {
if (propertyPath == null) {
return false;
}
@@ -137,7 +139,7 @@ public abstract class PropertyAccessorUtils {
* @param propertyName the bean property path
* @return the canonical representation of the property path
*/
- public static String canonicalPropertyName(String propertyName) {
+ public static String canonicalPropertyName(@Nullable String propertyName) {
if (propertyName == null) {
return "";
}
@@ -171,7 +173,8 @@ public abstract class PropertyAccessorUtils {
* (as array of the same size)
* @see #canonicalPropertyName(String)
*/
- public static String[] canonicalPropertyNames(String[] propertyNames) {
+ @Nullable
+ public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) {
if (propertyNames == null) {
return null;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java b/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java
index 64b7ca3b8c..b3bdfeabdd 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class PropertyBatchUpdateException extends BeansException {
* @param propertyAccessExceptions the List of PropertyAccessExceptions
*/
public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) {
- super(null);
+ super(null, null);
Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required");
this.propertyAccessExceptions = propertyAccessExceptions;
}
@@ -132,7 +132,7 @@ public class PropertyBatchUpdateException extends BeansException {
}
@Override
- public boolean contains(Class> exType) {
+ public boolean contains(@Nullable Class> exType) {
if (exType == null) {
return false;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java
index 5e766690af..84838d89fe 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Enumeration;
+import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -60,7 +61,10 @@ class PropertyDescriptorUtils {
/**
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
*/
- public static Class> findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException {
+ @Nullable
+ public static Class> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
+ throws IntrospectionException {
+
Class> propertyType = null;
if (readMethod != null) {
@@ -103,8 +107,9 @@ class PropertyDescriptorUtils {
/**
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
*/
- public static Class> findIndexedPropertyType(String name, Class> propertyType,
- Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
+ @Nullable
+ public static Class> findIndexedPropertyType(String name, @Nullable Class> propertyType,
+ @Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {
Class> indexedPropertyType = null;
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
index a44512fd81..7a16a30b58 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,7 +112,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* Specify a Spring 3.0 ConversionService to use for converting
* property values, as an alternative to JavaBeans PropertyEditors.
*/
- public void setConversionService(ConversionService conversionService) {
+ public void setConversionService(@Nullable ConversionService conversionService) {
this.conversionService = conversionService;
}
@@ -377,7 +377,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the custom editor, or {@code null} if none specific for this property
*/
@Nullable
- private PropertyEditor getCustomEditor(String propertyName, Class> requiredType) {
+ private PropertyEditor getCustomEditor(String propertyName, @Nullable Class> requiredType) {
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
}
@@ -391,7 +391,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @see java.beans.PropertyEditor#getAsText()
*/
@Nullable
- private PropertyEditor getCustomEditor(Class> requiredType) {
+ private PropertyEditor getCustomEditor(@Nullable Class> requiredType) {
if (requiredType == null || this.customEditors == null) {
return null;
}
@@ -521,7 +521,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private final Class> registeredType;
- private CustomEditorHolder(PropertyEditor propertyEditor, Class> registeredType) {
+ private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class> registeredType) {
this.propertyEditor = propertyEditor;
this.registeredType = registeredType;
}
@@ -530,11 +530,12 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
return this.propertyEditor;
}
+ @Nullable
private Class> getRegisteredType() {
return this.registeredType;
}
- private PropertyEditor getPropertyEditor(Class> requiredType) {
+ private PropertyEditor getPropertyEditor(@Nullable Class> requiredType) {
// Special case: If no required type specified, which usually only happens for
// Collection elements, or required type is not assignable to registered type,
// which usually only happens for generic properties of type Object -
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java
index 3c2f4e6c5b..e14689bc84 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.beans;
import java.io.Serializable;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -63,7 +64,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
* @param name the name of the property (never {@code null})
* @param value the value of the property (possibly before type conversion)
*/
- public PropertyValue(String name, Object value) {
+ public PropertyValue(String name, @Nullable Object value) {
+ Assert.notNull(name, "Name must not be null");
this.name = name;
this.value = value;
}
@@ -116,6 +118,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
* It is the responsibility of the BeanWrapper implementation to
* perform type conversion.
*/
+ @Nullable
public Object getValue() {
return this.value;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java
index cb2ac6cb17..786354aeb8 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public interface PropertyValues {
/**
* Return the property value with the given name, if any.
* @param propertyName the name to search for
- * @return the property value, or {@code null}
+ * @return the property value, or {@code null} if none
*/
@Nullable
PropertyValue getPropertyValue(String propertyName);
diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java
index 3cb9f6a5b1..5e38a1e93e 100644
--- a/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java
+++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,8 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
- T convertIfNecessary(Object value, @Nullable Class requiredType) throws TypeMismatchException;
+ @Nullable
+ T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException;
/**
* Convert the value to the required type (if necessary from a String).
@@ -68,8 +69,9 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
- T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam)
- throws TypeMismatchException;
+ @Nullable
+ T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType,
+ @Nullable MethodParameter methodParam) throws TypeMismatchException;
/**
* Convert the value to the required type (if necessary from a String).
@@ -87,7 +89,8 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
- T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable Field field)
+ @Nullable
+ T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field)
throws TypeMismatchException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
index ee5b7009dc..6b52d6a931 100644
--- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
+++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
@@ -75,7 +75,7 @@ class TypeConverterDelegate {
* @param propertyEditorRegistry the editor registry to use
* @param targetObject the target object to work on (as context that can be passed to editors)
*/
- public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject) {
+ public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, @Nullable Object targetObject) {
this.propertyEditorRegistry = propertyEditorRegistry;
this.targetObject = targetObject;
}
@@ -91,8 +91,9 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
- public T convertIfNecessary(Object newValue, @Nullable Class requiredType, @Nullable MethodParameter methodParam)
- throws IllegalArgumentException {
+ @Nullable
+ public T convertIfNecessary(@Nullable Object newValue, @Nullable Class requiredType,
+ @Nullable MethodParameter methodParam) throws IllegalArgumentException {
return convertIfNecessary(null, null, newValue, requiredType,
(methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
@@ -108,7 +109,8 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
- public T convertIfNecessary(Object newValue, @Nullable Class requiredType, @Nullable Field field)
+ @Nullable
+ public T convertIfNecessary(@Nullable Object newValue, @Nullable Class requiredType, @Nullable Field field)
throws IllegalArgumentException {
return convertIfNecessary(null, null, newValue, requiredType,
@@ -125,9 +127,9 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
- public T convertIfNecessary(
- String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class requiredType)
- throws IllegalArgumentException {
+ @Nullable
+ public T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
+ Object newValue, @Nullable Class requiredType) throws IllegalArgumentException {
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
}
@@ -145,8 +147,9 @@ class TypeConverterDelegate {
* @throws IllegalArgumentException if type conversion failed
*/
@SuppressWarnings("unchecked")
- public T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue,
- @Nullable Class requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException {
+ @Nullable
+ public T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
+ @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {
// Custom editor for this type?
PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);
@@ -268,7 +271,7 @@ class TypeConverterDelegate {
// Original exception from former ConversionService call above...
throw conversionAttemptEx;
}
- else if (conversionService != null) {
+ else if (conversionService != null && typeDescriptor != null) {
// ConversionService not tried before, probably custom editor found
// but editor couldn't produce the required type...
TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
@@ -359,7 +362,7 @@ class TypeConverterDelegate {
* @return the corresponding editor, or {@code null} if none
*/
@Nullable
- private PropertyEditor findDefaultEditor(Class> requiredType) {
+ private PropertyEditor findDefaultEditor(@Nullable Class> requiredType) {
PropertyEditor editor = null;
if (requiredType != null) {
// No custom editor -> check BeanWrapperImpl's default editors.
@@ -383,7 +386,10 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
- private Object doConvertValue(@Nullable Object oldValue, Object newValue, @Nullable Class> requiredType, PropertyEditor editor) {
+ @Nullable
+ private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
+ @Nullable Class> requiredType, @Nullable PropertyEditor editor) {
+
Object convertedValue = newValue;
if (editor != null && !(convertedValue instanceof String)) {
@@ -459,7 +465,7 @@ class TypeConverterDelegate {
return editor.getValue();
}
- private Object convertToTypedArray(Object input, String propertyName, Class> componentType) {
+ private Object convertToTypedArray(Object input, @Nullable String propertyName, Class> componentType) {
if (input instanceof Collection) {
// Convert Collection elements to array elements.
Collection> coll = (Collection>) input;
@@ -498,8 +504,8 @@ class TypeConverterDelegate {
}
@SuppressWarnings("unchecked")
- private Collection> convertToTypedCollection(
- Collection> original, String propertyName, Class> requiredType, TypeDescriptor typeDescriptor) {
+ private Collection> convertToTypedCollection(Collection> original, @Nullable String propertyName,
+ Class> requiredType, @Nullable TypeDescriptor typeDescriptor) {
if (!Collection.class.isAssignableFrom(requiredType)) {
return original;
@@ -515,7 +521,7 @@ class TypeConverterDelegate {
}
boolean originalAllowed = requiredType.isInstance(original);
- TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
+ TypeDescriptor elementType = (typeDescriptor != null ? typeDescriptor.getElementTypeDescriptor() : null);
if (elementType == null && originalAllowed &&
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
return original;
@@ -524,13 +530,6 @@ class TypeConverterDelegate {
Iterator> it;
try {
it = original.iterator();
- if (it == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("Collection of type [" + original.getClass().getName() +
- "] returned null Iterator - injecting original Collection as-is");
- }
- return original;
- }
}
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
@@ -580,8 +579,8 @@ class TypeConverterDelegate {
}
@SuppressWarnings("unchecked")
- private Map, ?> convertToTypedMap(
- Map, ?> original, String propertyName, Class> requiredType, TypeDescriptor typeDescriptor) {
+ private Map, ?> convertToTypedMap(Map, ?> original, @Nullable String propertyName,
+ Class> requiredType, @Nullable TypeDescriptor typeDescriptor) {
if (!Map.class.isAssignableFrom(requiredType)) {
return original;
@@ -597,8 +596,8 @@ class TypeConverterDelegate {
}
boolean originalAllowed = requiredType.isInstance(original);
- TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor();
- TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor();
+ TypeDescriptor keyType = (typeDescriptor != null ? typeDescriptor.getMapKeyTypeDescriptor() : null);
+ TypeDescriptor valueType = (typeDescriptor != null ? typeDescriptor.getMapValueTypeDescriptor() : null);
if (keyType == null && valueType == null && originalAllowed &&
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
return original;
@@ -607,13 +606,6 @@ class TypeConverterDelegate {
Iterator> it;
try {
it = original.entrySet().iterator();
- if (it == null) {
- if (logger.isDebugEnabled()) {
- logger.debug("Map of type [" + original.getClass().getName() +
- "] returned null Iterator - injecting original Map as-is");
- }
- return original;
- }
}
catch (Throwable ex) {
if (logger.isDebugEnabled()) {
@@ -665,13 +657,15 @@ class TypeConverterDelegate {
return (originalAllowed ? original : convertedCopy);
}
- private String buildIndexedPropertyName(String propertyName, int index) {
+ @Nullable
+ private String buildIndexedPropertyName(@Nullable String propertyName, int index) {
return (propertyName != null ?
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
null);
}
- private String buildKeyedPropertyName(String propertyName, Object key) {
+ @Nullable
+ private String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
return (propertyName != null ?
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
null);
diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java
index e45d8ef084..b73832453f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java
+++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java
@@ -37,26 +37,28 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
@Override
- public T convertIfNecessary(Object value, @Nullable Class requiredType) throws TypeMismatchException {
+ public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException {
return doConvert(value, requiredType, null, null);
}
@Override
- public T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam)
+ public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam)
throws TypeMismatchException {
return doConvert(value, requiredType, methodParam, null);
}
@Override
- public T convertIfNecessary(Object value, @Nullable Class requiredType, @Nullable Field field)
+ public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field)
throws TypeMismatchException {
return doConvert(value, requiredType, null, field);
}
- private T doConvert(Object value, Class requiredType, @Nullable MethodParameter methodParam, @Nullable Field field)
- throws TypeMismatchException {
+ @Nullable
+ private T doConvert(@Nullable Object value,@Nullable Class requiredType,
+ @Nullable MethodParameter methodParam, @Nullable Field field) throws TypeMismatchException {
+
try {
if (field != null) {
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field);
@@ -65,16 +67,10 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
}
}
- catch (ConverterNotFoundException ex) {
+ catch (ConverterNotFoundException | IllegalStateException ex) {
throw new ConversionNotSupportedException(value, requiredType, ex);
}
- catch (ConversionException ex) {
- throw new TypeMismatchException(value, requiredType, ex);
- }
- catch (IllegalStateException ex) {
- throw new ConversionNotSupportedException(value, requiredType, ex);
- }
- catch (IllegalArgumentException ex) {
+ catch (ConversionException | IllegalArgumentException ex) {
throw new TypeMismatchException(value, requiredType, ex);
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java
index 2fe07446ab..83c3614985 100644
--- a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java
@@ -56,7 +56,9 @@ public class TypeMismatchException extends PropertyAccessException {
* @param requiredType the required target type (or {@code null} if not known)
* @param cause the root cause (may be {@code null})
*/
- public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class> requiredType, @Nullable Throwable cause) {
+ public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class> requiredType,
+ @Nullable Throwable cause) {
+
super(propertyChangeEvent,
"Failed to convert property value of type '" +
ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
diff --git a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
index 6f5a198b7d..5847e8bb54 100644
--- a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public abstract class AnnotationBeanUtils {
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
- public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable String... excludedProperties) {
+ public static void copyPropertiesToBean(Annotation ann, Object bean, String... excludedProperties) {
copyPropertiesToBean(ann, bean, null, excludedProperties);
}
@@ -59,7 +59,9 @@ public abstract class AnnotationBeanUtils {
* @param excludedProperties the names of excluded properties, if any
* @see org.springframework.beans.BeanWrapper
*/
- public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, @Nullable String... excludedProperties) {
+ public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver,
+ String... excludedProperties) {
+
Set excluded = new HashSet<>(Arrays.asList(excludedProperties));
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java
index 5249a93e4c..58b62df606 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanClassLoaderAware.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package org.springframework.beans.factory;
-import org.springframework.lang.Nullable;
-
/**
* Callback that allows a bean to be aware of the bean
* {@link ClassLoader class loader}; that is, the class loader used by the
@@ -47,11 +45,8 @@ public interface BeanClassLoaderAware extends Aware {
* {@link InitializingBean InitializingBean's}
* {@link InitializingBean#afterPropertiesSet()}
* method or a custom init-method.
- * @param classLoader the owning class loader; may be {@code null} in
- * which case a default {@code ClassLoader} must be used, for example
- * the {@code ClassLoader} obtained via
- * {@link org.springframework.util.ClassUtils#getDefaultClassLoader()}
+ * @param classLoader the owning class loader
*/
- void setBeanClassLoader(@Nullable ClassLoader classLoader);
+ void setBeanClassLoader(ClassLoader classLoader);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java
index 16b2966c7f..157303b219 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanCreationException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public class BeanCreationException extends FatalBeanException {
* @param msg the detail message
*/
public BeanCreationException(String beanName, String msg) {
- super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") + ": " + msg);
+ super("Error creating bean with name '" + beanName + "': " + msg);
this.beanName = beanName;
}
@@ -86,8 +86,8 @@ public class BeanCreationException extends FatalBeanException {
* @param beanName the name of the bean requested
* @param msg the detail message
*/
- public BeanCreationException(String resourceDescription, String beanName, String msg) {
- super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") +
+ public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, String msg) {
+ super("Error creating bean with name '" + beanName + "'" +
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
this.resourceDescription = resourceDescription;
this.beanName = beanName;
@@ -101,20 +101,12 @@ public class BeanCreationException extends FatalBeanException {
* @param msg the detail message
* @param cause the root cause
*/
- public BeanCreationException(String resourceDescription, String beanName, String msg, Throwable cause) {
+ public BeanCreationException(@Nullable String resourceDescription, String beanName, String msg, Throwable cause) {
this(resourceDescription, beanName, msg);
initCause(cause);
}
- /**
- * Return the name of the bean requested, if any.
- */
- @Nullable
- public String getBeanName() {
- return this.beanName;
- }
-
/**
* Return the description of the resource that the bean
* definition came from, if any.
@@ -124,6 +116,13 @@ public class BeanCreationException extends FatalBeanException {
return this.resourceDescription;
}
+ /**
+ * Return the name of the bean requested, if any.
+ */
+ public String getBeanName() {
+ return this.beanName;
+ }
+
/**
* Add a related cause to this bean creation exception,
* not being a direct cause of the failure but having occurred
@@ -189,7 +188,7 @@ public class BeanCreationException extends FatalBeanException {
}
@Override
- public boolean contains(Class> exClass) {
+ public boolean contains(@Nullable Class> exClass) {
if (super.contains(exClass)) {
return true;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java
index a870277500..a568c9688d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanDefinitionStoreException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
* @param resourceDescription description of the resource that the bean definition came from
* @param msg the detail message (used as exception message as-is)
*/
- public BeanDefinitionStoreException(String resourceDescription, String msg) {
+ public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) {
super(msg);
this.resourceDescription = resourceDescription;
}
@@ -68,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
* @param msg the detail message (used as exception message as-is)
* @param cause the root cause (may be {@code null})
*/
- public BeanDefinitionStoreException(String resourceDescription, String msg, @Nullable Throwable cause) {
+ public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) {
super(msg, cause);
this.resourceDescription = resourceDescription;
}
@@ -80,7 +80,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
* @param msg the detail message (appended to an introductory message that indicates
* the resource and the name of the bean)
*/
- public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) {
+ public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg) {
this(resourceDescription, beanName, msg, null);
}
@@ -92,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
* the resource and the name of the bean)
* @param cause the root cause (may be {@code null})
*/
- public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
+ public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
this.resourceDescription = resourceDescription;
this.beanName = beanName;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
index c0837c6dcc..d3bfa88f66 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -159,6 +159,22 @@ public interface BeanFactory {
*/
T getBean(String name, @Nullable Class requiredType) throws BeansException;
+ /**
+ * Return an instance, which may be shared or independent, of the specified bean.
+ * Allows for specifying explicit constructor arguments / factory method arguments,
+ * overriding the specified default arguments (if any) in the bean definition.
+ * @param name the name of the bean to retrieve
+ * @param args arguments to use when creating a bean instance using explicit arguments
+ * (only applied when creating a new instance as opposed to retrieving an existing one)
+ * @return an instance of the bean
+ * @throws NoSuchBeanDefinitionException if there is no such bean definition
+ * @throws BeanDefinitionStoreException if arguments have been given but
+ * the affected bean isn't a prototype
+ * @throws BeansException if the bean could not be created
+ * @since 2.5
+ */
+ Object getBean(String name, Object... args) throws BeansException;
+
/**
* Return the bean instance that uniquely matches the given object type, if any.
*
This method goes into {@link ListableBeanFactory} by-type lookup territory
@@ -176,22 +192,6 @@ public interface BeanFactory {
*/
T getBean(Class requiredType) throws BeansException;
- /**
- * Return an instance, which may be shared or independent, of the specified bean.
- * Allows for specifying explicit constructor arguments / factory method arguments,
- * overriding the specified default arguments (if any) in the bean definition.
- * @param name the name of the bean to retrieve
- * @param args arguments to use when creating a bean instance using explicit arguments
- * (only applied when creating a new instance as opposed to retrieving an existing one)
- * @return an instance of the bean
- * @throws NoSuchBeanDefinitionException if there is no such bean definition
- * @throws BeanDefinitionStoreException if arguments have been given but
- * the affected bean isn't a prototype
- * @throws BeansException if the bean could not be created
- * @since 2.5
- */
- Object getBean(String name, Object... args) throws BeansException;
-
/**
* Return an instance, which may be shared or independent, of the specified bean.
*
Allows for specifying explicit constructor arguments / factory method arguments,
@@ -298,7 +298,7 @@ public interface BeanFactory {
* @see #getBean
* @see #getType
*/
- boolean isTypeMatch(String name, Class> typeToMatch) throws NoSuchBeanDefinitionException;
+ boolean isTypeMatch(String name, @Nullable Class> typeToMatch) throws NoSuchBeanDefinitionException;
/**
* Determine the type of the bean with the given name. More specifically,
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
index 39bdea9c0d..c69dad3929 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -57,7 +58,7 @@ public abstract class BeanFactoryUtils {
* @return whether the given name is a factory dereference
* @see BeanFactory#FACTORY_BEAN_PREFIX
*/
- public static boolean isFactoryDereference(String name) {
+ public static boolean isFactoryDereference(@Nullable String name) {
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
}
@@ -86,7 +87,7 @@ public abstract class BeanFactoryUtils {
* @see org.springframework.beans.factory.support.BeanDefinitionReaderUtils#generateBeanName
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
*/
- public static boolean isGeneratedBeanName(String name) {
+ public static boolean isGeneratedBeanName(@Nullable String name) {
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java
index 772da666e2..9bd6127f3d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.beans.factory;
import org.springframework.beans.FatalBeanException;
+import org.springframework.lang.Nullable;
/**
* Exception thrown when the BeanFactory cannot load the specified class
@@ -44,10 +45,10 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* @param cause the root cause
*/
public CannotLoadBeanClassException(
- String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) {
+ @Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
- super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName +
- "' defined in " + resourceDescription, cause);
+ super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
+ (resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
this.resourceDescription = resourceDescription;
this.beanName = beanName;
this.beanClassName = beanClassName;
@@ -62,10 +63,11 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* @param cause the root cause
*/
public CannotLoadBeanClassException(
- String resourceDescription, String beanName, String beanClassName, LinkageError cause) {
+ @Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
- super("Error loading class [" + beanClassName + "] for bean with name '" + beanName +
- "' defined in " + resourceDescription + ": problem with class file or dependent class", cause);
+ super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
+ (resourceDescription != null ? " defined in " + resourceDescription : "") +
+ ": problem with class file or dependent class", cause);
this.resourceDescription = resourceDescription;
this.beanName = beanName;
this.beanClassName = beanClassName;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java
index 4b7dea51cd..e2b841f0da 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java
@@ -106,7 +106,7 @@ public interface ListableBeanFactory extends BeanFactory {
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
*
Bean names returned by this method should always return bean names in the
* order of definition in the backend configuration, as far as possible.
- * @param type the class or interface to match, or {@code null} for all bean names
+ * @param type the generically typed class or interface to match
* @return the names of beans (or objects created by FactoryBeans) matching
* the given object type (including subclasses), or an empty array if none
* @since 4.2
@@ -114,7 +114,7 @@ public interface ListableBeanFactory extends BeanFactory {
* @see FactoryBean#getObjectType
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
*/
- String[] getBeanNamesForType(@Nullable ResolvableType type);
+ String[] getBeanNamesForType(ResolvableType type);
/**
* Return the names of beans matching the given type (including subclasses),
@@ -268,7 +268,7 @@ public interface ListableBeanFactory extends BeanFactory {
* found on the given class itself.
* @param beanName the name of the bean to look for annotations on
* @param annotationType the annotation class to look for
- * @return the annotation of the given type if found, or {@code null}
+ * @return the annotation of the given type if found, or {@code null} otherwise
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
* @since 3.0
*/
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectFactory.java
index 0710f343aa..c92456f650 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.beans.factory;
import org.springframework.beans.BeansException;
+import org.springframework.lang.Nullable;
/**
* Defines a factory which can return an Object instance
@@ -41,9 +42,10 @@ public interface ObjectFactory {
/**
* Return an instance (possibly shared or independent)
* of the object managed by this factory.
- * @return an instance of the bean (should never be {@code null})
+ * @return the resulting instance
* @throws BeansException in case of creation errors
*/
+ @Nullable
T getObject() throws BeansException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java
index de71971894..9fd5736416 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java
@@ -40,6 +40,7 @@ public interface ObjectProvider extends ObjectFactory {
* @throws BeansException in case of creation errors
* @see #getObject()
*/
+ @Nullable
T getObject(Object... args) throws BeansException;
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
index f763aad22c..9d5b3082d5 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
@@ -228,10 +228,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class> beanType, String beanName) {
- if (beanType != null) {
- InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
- metadata.checkConfigMembers(beanDefinition);
- }
+ InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
+ metadata.checkConfigMembers(beanDefinition);
}
@Override
@@ -389,7 +387,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
- private InjectionMetadata findAutowiringMetadata(String beanName, Class> clazz, PropertyValues pvs) {
+ private InjectionMetadata findAutowiringMetadata(String beanName, Class> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@@ -512,7 +510,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
/**
* Register the specified bean as dependent on the autowired beans.
*/
- private void registerDependentBeans(String beanName, Set autowiredBeanNames) {
+ private void registerDependentBeans(@Nullable String beanName, Set autowiredBeanNames) {
if (beanName != null) {
for (String autowiredBeanName : autowiredBeanNames) {
if (this.beanFactory.containsBean(autowiredBeanName)) {
@@ -529,7 +527,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
/**
* Resolve the specified cached method argument or field value.
*/
- private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
+ @Nullable
+ private Object resolvedCachedArgument(@Nullable String beanName, Object cachedArgument) {
if (cachedArgument instanceof DependencyDescriptor) {
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
@@ -557,7 +556,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
@Override
- protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
+ protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
Field field = (Field) this.member;
Object value;
if (this.cached) {
@@ -615,13 +614,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private volatile Object[] cachedMethodArguments;
- public AutowiredMethodElement(Method method, boolean required, PropertyDescriptor pd) {
+ public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
super(method, pd);
this.required = required;
}
@Override
- protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
+ protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
if (checkPropertySkipping(pvs)) {
return;
}
@@ -694,7 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
@Nullable
- private Object[] resolveCachedArguments(String beanName) {
+ private Object[] resolveCachedArguments(@Nullable String beanName) {
if (this.cachedMethodArguments == null) {
return null;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java
index 882649e354..8a9b4b6414 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -120,7 +121,9 @@ public abstract class BeanFactoryAnnotationUtils {
* qualifier value (through {@code } or {@code @Qualifier})
* @since 5.0
*/
- public static boolean isQualifierMatch(Predicate qualifier, String beanName, BeanFactory beanFactory) {
+ public static boolean isQualifierMatch(Predicate qualifier, String beanName,
+ @Nullable BeanFactory beanFactory) {
+
// Try quick bean name or alias match first...
if (qualifier.test(beanName)) {
return true;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
index d1abb0021b..8916da2cd1 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
@@ -121,10 +121,8 @@ public class InitDestroyAnnotationBeanPostProcessor
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class> beanType, String beanName) {
- if (beanType != null) {
- LifecycleMetadata metadata = findLifecycleMetadata(beanType);
- metadata.checkConfigMembers(beanDefinition);
- }
+ LifecycleMetadata metadata = findLifecycleMetadata(beanType);
+ metadata.checkConfigMembers(beanDefinition);
}
@Override
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java
index 7021f8c3ab..1316b0ff46 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public class InjectionMetadata {
this.checkedElements = checkedElements;
}
- public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable {
+ public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
Collection elementsToIterate =
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) {
@@ -94,7 +94,7 @@ public class InjectionMetadata {
/**
* @since 3.2.13
*/
- public void clear(PropertyValues pvs) {
+ public void clear(@Nullable PropertyValues pvs) {
Collection elementsToIterate =
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) {
@@ -105,7 +105,7 @@ public class InjectionMetadata {
}
- public static boolean needsRefresh(InjectionMetadata metadata, Class> clazz) {
+ public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class> clazz) {
return (metadata == null || metadata.targetClass != clazz);
}
@@ -120,7 +120,7 @@ public class InjectionMetadata {
protected volatile Boolean skip;
- protected InjectedElement(Member member, PropertyDescriptor pd) {
+ protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
this.member = member;
this.isField = (member instanceof Field);
this.pd = pd;
@@ -163,7 +163,9 @@ public class InjectionMetadata {
/**
* Either this or {@link #getResourceToInject} needs to be overridden.
*/
- protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
+ protected void inject(Object target, @Nullable String requestingBeanName, @Nullable PropertyValues pvs)
+ throws Throwable {
+
if (this.isField) {
Field field = (Field) this.member;
ReflectionUtils.makeAccessible(field);
@@ -189,7 +191,7 @@ public class InjectionMetadata {
* an explicit property value having been specified. Also marks the
* affected property as processed for other processors to ignore it.
*/
- protected boolean checkPropertySkipping(PropertyValues pvs) {
+ protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
if (this.skip != null) {
return this.skip;
}
@@ -219,7 +221,7 @@ public class InjectionMetadata {
/**
* @since 3.2.13
*/
- protected void clearPropertySkipping(PropertyValues pvs) {
+ protected void clearPropertySkipping(@Nullable PropertyValues pvs) {
if (pvs == null) {
return;
}
@@ -234,7 +236,7 @@ public class InjectionMetadata {
* Either this or {@link #inject} needs to be overridden.
*/
@Nullable
- protected Object getResourceToInject(Object target, String requestingBeanName) {
+ protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
return null;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java
index e33fd4c889..35fc98e21f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java
@@ -145,7 +145,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
@Override
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
- if (match && descriptor != null) {
+ if (match) {
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
if (match) {
MethodParameter methodParam = descriptor.getMethodParameter();
@@ -298,11 +298,13 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
return true;
}
+ @Nullable
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class extends Annotation> type) {
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
}
+ @Nullable
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class extends Annotation> type) {
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
index b2cedcb271..3df0f5178d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ import org.springframework.core.Conventions;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -170,7 +171,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
* @param beanName the name of the bean to check against
* @return {@code true} to skip the bean; {@code false} to process it
*/
- protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
+ protected boolean shouldSkip(@Nullable ConfigurableListableBeanFactory beanFactory, String beanName) {
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
return false;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java
index 087eb91373..625bb2cd5f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AbstractFactoryBean.java
@@ -91,7 +91,7 @@ public abstract class AbstractFactoryBean
}
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java
index 4c0fab3b03..1a43bb9bfd 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowireCapableBeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -268,6 +268,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @return the bean instance to use, either the original or a wrapped one
* @throws BeansException if the initialization failed
*/
+ @Nullable
Object initializeBean(Object existingBean, String beanName) throws BeansException;
/**
@@ -280,6 +281,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @throws BeansException if any post-processing failed
* @see BeanPostProcessor#postProcessBeforeInitialization
*/
+ @Nullable
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
throws BeansException;
@@ -293,6 +295,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @throws BeansException if any post-processing failed
* @see BeanPostProcessor#postProcessAfterInitialization
*/
+ @Nullable
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
throws BeansException;
@@ -356,7 +359,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @see DependencyDescriptor
*/
@Nullable
- Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
+ Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
@Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java
index 8cd218573f..715c57b7e6 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #setFactoryBeanName
* @see #setFactoryMethodName
*/
- void setBeanClassName(String beanClassName);
+ void setBeanClassName(@Nullable String beanClassName);
/**
* Return the current bean class name of this bean definition.
@@ -115,6 +115,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #getFactoryBeanName()
* @see #getFactoryMethodName()
*/
+ @Nullable
String getBeanClassName();
/**
@@ -122,11 +123,10 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #SCOPE_SINGLETON
* @see #SCOPE_PROTOTYPE
*/
- void setScope(String scope);
+ void setScope(@Nullable String scope);
/**
- * Return the name of the current target scope for this bean,
- * or {@code null} if not known yet.
+ * Return the name of the current target scope for this bean.
*/
@Nullable
String getScope();
@@ -153,6 +153,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return the bean names that this bean depends on.
*/
+ @Nullable
String[] getDependsOn();
/**
@@ -186,7 +187,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* This the name of the bean to call the specified factory method on.
* @see #setFactoryMethodName
*/
- void setFactoryBeanName(String factoryBeanName);
+ void setFactoryBeanName(@Nullable String factoryBeanName);
/**
* Return the factory bean name, if any.
@@ -202,7 +203,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #setFactoryBeanName
* @see #setBeanClassName
*/
- void setFactoryMethodName(String factoryMethodName);
+ void setFactoryMethodName(@Nullable String factoryMethodName);
/**
* Return a factory method, if any.
@@ -259,6 +260,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return a human-readable description of this bean definition.
*/
+ @Nullable
String getDescription();
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java
index 9379a831af..6e831ef546 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
* Determine whether the given candidate name matches the bean name
* or the aliases stored in this bean definition.
*/
- public boolean matchesName(String candidateName) {
+ public boolean matchesName(@Nullable String candidateName) {
return (candidateName != null && (candidateName.equals(this.beanName) ||
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
ObjectUtils.containsElement(this.aliases, candidateName)));
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
index 22b3bccdbc..6b0f1555be 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import java.util.Set;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringValueResolver;
@@ -164,7 +165,8 @@ public class BeanDefinitionVisitor {
}
@SuppressWarnings("rawtypes")
- protected Object resolveValue(Object value) {
+ @Nullable
+ protected Object resolveValue(@Nullable Object value) {
if (value instanceof BeanDefinition) {
visitBeanDefinition((BeanDefinition) value);
}
@@ -174,6 +176,9 @@ public class BeanDefinitionVisitor {
else if (value instanceof RuntimeBeanReference) {
RuntimeBeanReference ref = (RuntimeBeanReference) value;
String newBeanName = resolveStringValue(ref.getBeanName());
+ if (newBeanName == null) {
+ return null;
+ }
if (!newBeanName.equals(ref.getBeanName())) {
return new RuntimeBeanReference(newBeanName);
}
@@ -181,6 +186,9 @@ public class BeanDefinitionVisitor {
else if (value instanceof RuntimeBeanNameReference) {
RuntimeBeanNameReference ref = (RuntimeBeanNameReference) value;
String newBeanName = resolveStringValue(ref.getBeanName());
+ if (newBeanName == null) {
+ return null;
+ }
if (!newBeanName.equals(ref.getBeanName())) {
return new RuntimeBeanNameReference(newBeanName);
}
@@ -274,6 +282,7 @@ public class BeanDefinitionVisitor {
* @param strVal the original String value
* @return the resolved String value
*/
+ @Nullable
protected String resolveStringValue(String strVal) {
if (this.valueResolver == null) {
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java
index 3b2604f15a..1b025ad657 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.beans.factory.config;
import org.springframework.beans.BeansException;
+import org.springframework.lang.Nullable;
/**
* Strategy interface for resolving a value through evaluating it
@@ -40,6 +41,7 @@ public interface BeanExpressionResolver {
* @return the resolved value (potentially the given value as-is)
* @throws BeansException if evaluation failed
*/
- Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException;
+ @Nullable
+ Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
index d73cc44916..0f375fb560 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,12 +134,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* here, supporting "#{...}" expressions in a Unified EL compatible style.
* @since 3.0
*/
- void setBeanExpressionResolver(BeanExpressionResolver resolver);
+ void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver);
/**
* Return the resolution strategy for expressions in bean definition values.
* @since 3.0
*/
+ @Nullable
BeanExpressionResolver getBeanExpressionResolver();
/**
@@ -147,7 +148,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* property values, as an alternative to JavaBeans PropertyEditors.
* @since 3.0
*/
- void setConversionService(ConversionService conversionService);
+ void setConversionService(@Nullable ConversionService conversionService);
/**
* Return the associated ConversionService, if any.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java
index 8899a904c4..2f0afba413 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public interface ConfigurableListableBeanFactory
* implementation of the {@link org.springframework.beans.factory.ObjectFactory}
* interface, which allows for lazy resolution of the actual target value.
*/
- void registerResolvableDependency(Class> dependencyType, Object autowiredValue);
+ void registerResolvableDependency(Class> dependencyType, @Nullable Object autowiredValue);
/**
* Determine whether the specified bean qualifies as an autowire candidate,
@@ -106,7 +106,7 @@ public interface ConfigurableListableBeanFactory
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
* defined in this factory
*/
- BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException;
+ BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
/**
* Return a unified view over all bean names managed by this factory.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
index 54d157bfdf..e9aced9f9e 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class ConstructorArgumentValues {
* to allow for merging and re-merging of argument value definitions. Distinct
* ValueHolder instances carrying the same content are of course allowed.
*/
- public void addArgumentValues(ConstructorArgumentValues other) {
+ public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
if (other != null) {
for (Map.Entry entry : other.indexedArgumentValues.entrySet()) {
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
@@ -89,7 +89,7 @@ public class ConstructorArgumentValues {
* @param index the index in the constructor argument list
* @param value the argument value
*/
- public void addIndexedArgumentValue(int index, Object value) {
+ public void addIndexedArgumentValue(int index, @Nullable Object value) {
addIndexedArgumentValue(index, new ValueHolder(value));
}
@@ -99,7 +99,7 @@ public class ConstructorArgumentValues {
* @param value the argument value
* @param type the type of the constructor argument
*/
- public void addIndexedArgumentValue(int index, Object value, String type) {
+ public void addIndexedArgumentValue(int index, @Nullable Object value, String type) {
addIndexedArgumentValue(index, new ValueHolder(value, type));
}
@@ -453,7 +453,7 @@ public class ConstructorArgumentValues {
* Create a new ValueHolder for the given value.
* @param value the argument value
*/
- public ValueHolder(Object value) {
+ public ValueHolder(@Nullable Object value) {
this.value = value;
}
@@ -462,7 +462,7 @@ public class ConstructorArgumentValues {
* @param value the argument value
* @param type the type of the constructor argument
*/
- public ValueHolder(Object value, String type) {
+ public ValueHolder(@Nullable Object value, @Nullable String type) {
this.value = value;
this.type = type;
}
@@ -473,7 +473,7 @@ public class ConstructorArgumentValues {
* @param type the type of the constructor argument
* @param name the name of the constructor argument
*/
- public ValueHolder(Object value, String type, String name) {
+ public ValueHolder(@Nullable Object value, @Nullable String type, @Nullable String name) {
this.value = value;
this.type = type;
this.name = name;
@@ -483,13 +483,14 @@ public class ConstructorArgumentValues {
* Set the value for the constructor argument.
* @see PropertyPlaceholderConfigurer
*/
- public void setValue(Object value) {
+ public void setValue(@Nullable Object value) {
this.value = value;
}
/**
* Return the value for the constructor argument.
*/
+ @Nullable
public Object getValue() {
return this.value;
}
@@ -497,13 +498,14 @@ public class ConstructorArgumentValues {
/**
* Set the type of the constructor argument.
*/
- public void setType(String type) {
+ public void setType(@Nullable String type) {
this.type = type;
}
/**
* Return the type of the constructor argument.
*/
+ @Nullable
public String getType() {
return this.type;
}
@@ -511,13 +513,14 @@ public class ConstructorArgumentValues {
/**
* Set the name of the constructor argument.
*/
- public void setName(String name) {
+ public void setName(@Nullable String name) {
this.name = name;
}
/**
* Return the name of the constructor argument.
*/
+ @Nullable
public String getName() {
return this.name;
}
@@ -526,11 +529,12 @@ public class ConstructorArgumentValues {
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
@Override
+ @Nullable
public Object getSource() {
return this.source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java
index 3b6288fc3b..8c187ab2ff 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java
@@ -99,12 +99,9 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
this.declaringClass = methodParameter.getDeclaringClass();
if (this.methodParameter.getMethod() != null) {
- this.methodName = methodParameter.getMethod().getName();
- this.parameterTypes = methodParameter.getMethod().getParameterTypes();
- }
- else {
- this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
+ this.methodName = this.methodParameter.getMethod().getName();
}
+ this.parameterTypes = methodParameter.getExecutable().getParameterTypes();
this.parameterIndex = methodParameter.getParameterIndex();
this.containingClass = methodParameter.getContainingClass();
this.required = required;
@@ -334,6 +331,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
* Determine the name of the wrapped parameter/field.
* @return the declared name (never {@code null})
*/
+ @Nullable
public String getDependencyName() {
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/DeprecatedBeanWarner.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/DeprecatedBeanWarner.java
index 893e4c2016..64fb2af6bd 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/DeprecatedBeanWarner.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/DeprecatedBeanWarner.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,6 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
*
This can be specified to not log into the category of this warner class but rather
* into a specific named category.
* @see org.apache.commons.logging.LogFactory#getLog(String)
- * @see org.apache.log4j.Logger#getLogger(String)
* @see java.util.logging.Logger#getLogger(String)
*/
public void setLoggerName(String loggerName) {
@@ -61,10 +60,13 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
if (beanFactory.isFactoryBean(beanName)) {
nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
}
- Class> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
- if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
- BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
- logDeprecatedBean(beanName, beanType, beanDefinition);
+ Class> beanType = beanFactory.getType(nameToLookup);
+ if (beanType != null) {
+ Class> userClass = ClassUtils.getUserClass(beanType);
+ if (userClass.isAnnotationPresent(Deprecated.class)) {
+ BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
+ logDeprecatedBean(beanName, beanType, beanDefinition);
+ }
}
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java
index 2f44edeb55..921a0ed555 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.beans.factory.config;
-import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
/**
@@ -48,7 +47,7 @@ public class EmbeddedValueResolver implements StringValueResolver {
@Override
- public String resolveStringValue(@Nullable String strVal) {
+ public String resolveStringValue(String strVal) {
String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal);
if (this.exprResolver != null && value != null) {
Object evaluated = this.exprResolver.evaluate(value, this.exprContext);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java
index de5221e978..8b6a25e8dc 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java
@@ -149,7 +149,7 @@ public class FieldRetrievingFactoryBean
}
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java
index 2462506bc8..4a4cfe7816 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java
@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.ResolvableType;
+import org.springframework.lang.Nullable;
/**
* Simple factory for shared List instances. Allows for central setup
@@ -54,7 +55,7 @@ public class ListFactoryBean extends AbstractFactoryBean> {
* @see java.util.ArrayList
*/
@SuppressWarnings("rawtypes")
- public void setTargetListClass(Class extends List> targetListClass) {
+ public void setTargetListClass(@Nullable Class extends List> targetListClass) {
if (targetListClass == null) {
throw new IllegalArgumentException("'targetListClass' must not be null");
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java
index 542487fa3b..76b6a015e5 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java
@@ -22,6 +22,7 @@ import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.ResolvableType;
+import org.springframework.lang.Nullable;
/**
* Simple factory for shared Map instances. Allows for central setup
@@ -54,7 +55,7 @@ public class MapFactoryBean extends AbstractFactoryBean> {
* @see java.util.LinkedHashMap
*/
@SuppressWarnings("rawtypes")
- public void setTargetMapClass(Class extends Map> targetMapClass) {
+ public void setTargetMapClass(@Nullable Class extends Map> targetMapClass) {
if (targetMapClass == null) {
throw new IllegalArgumentException("'targetMapClass' must not be null");
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java
index e0c49ba7d2..f9d087274c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-20147 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.
@@ -73,7 +73,7 @@ public class MethodInvokingBean extends ArgumentConvertingMethodInvoker
@Override
- public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
+ public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
@@ -115,6 +115,7 @@ public class MethodInvokingBean extends ArgumentConvertingMethodInvoker
* Perform the invocation and convert InvocationTargetException
* into the underlying target exception.
*/
+ @Nullable
protected Object invokeWithTargetException() throws Exception {
try {
return invoke();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java
index 0c43b97c31..17ca9c6a96 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/NamedBeanHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ public class NamedBeanHolder implements NamedBean {
* @param beanName the name of the bean
* @param beanInstance the corresponding bean instance
*/
- public NamedBeanHolder(String beanName, T beanInstance) {
+ public NamedBeanHolder(String beanName, @Nullable T beanInstance) {
Assert.notNull(beanName, "Bean name must not be null");
this.beanName = beanName;
this.beanInstance = beanInstance;
@@ -47,7 +47,7 @@ public class NamedBeanHolder implements NamedBean {
/**
- * Return the name of the bean (never {@code null}).
+ * Return the name of the bean.
*/
@Override
public String getBeanName() {
@@ -55,9 +55,8 @@ public class NamedBeanHolder implements NamedBean {
}
/**
- * Return the corresponding bean instance (can be {@code null}).
+ * Return the corresponding bean instance.
*/
- @Nullable
public T getBeanInstance() {
return this.beanInstance;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java
index 89f41a126d..334699eca6 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PreferencesPlaceholderConfigurer.java
@@ -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.
@@ -115,7 +115,7 @@ public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigu
* @return the value for the placeholder, or {@code null} if none found
*/
@Nullable
- protected String resolvePlaceholder(String path, String key, Preferences preferences) {
+ protected String resolvePlaceholder(@Nullable String path, String key, Preferences preferences) {
if (path != null) {
// Do not create the node if it does not exist...
try {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java
index 0d2f275eae..f89593c522 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java
@@ -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.
@@ -144,12 +144,14 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer {
ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
BeanDefinition bd = factory.getBeanDefinition(beanName);
- while (bd.getOriginatingBeanDefinition() != null) {
+ BeanDefinition bdToUse = bd;
+ while (bd != null) {
+ bdToUse = bd;
bd = bd.getOriginatingBeanDefinition();
}
PropertyValue pv = new PropertyValue(property, value);
pv.setOptional(this.ignoreInvalidKeys);
- bd.getPropertyValues().addPropertyValue(pv);
+ bdToUse.getPropertyValues().addPropertyValue(pv);
}
@@ -157,8 +159,7 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer {
* Were there overrides for this bean?
* Only valid after processing has occurred at least once.
* @param beanName name of the bean to query status for
- * @return whether there were property overrides for
- * the named bean
+ * @return whether there were property overrides for the named bean
*/
public boolean hasPropertyOverridesFor(String beanName) {
return this.beanNames.contains(beanName);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
index aa0848a86c..6aa5551fd2 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
@@ -153,6 +153,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
* @see System#getProperty
* @see #resolvePlaceholder(String, java.util.Properties)
*/
+ @Nullable
protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) {
String propVal = null;
if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) {
@@ -238,8 +239,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
}
@Override
- @Nullable
- public String resolveStringValue(@Nullable String strVal) throws BeansException {
+ public String resolveStringValue(String strVal) throws BeansException {
String resolved = this.helper.replacePlaceholders(strVal, this.resolver);
if (trimValues) {
resolved = resolved.trim();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java
index e6f4a2f9d2..7f40ce0479 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.beans.factory.config;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -53,7 +54,7 @@ public class RuntimeBeanNameReference implements BeanReference {
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java
index 1590491992..8a3019b066 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.beans.factory.config;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -78,7 +79,7 @@ public class RuntimeBeanReference implements BeanReference {
* Set the configuration source {@code Object} for this metadata element.
*
The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
index 92345d7eab..0f0e4b1fa5 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
@@ -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.
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
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.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -223,10 +224,6 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto
* @see #createServiceLocatorException
*/
public void setServiceLocatorExceptionClass(Class extends Exception> serviceLocatorExceptionClass) {
- if (serviceLocatorExceptionClass != null && !Exception.class.isAssignableFrom(serviceLocatorExceptionClass)) {
- throw new IllegalArgumentException(
- "serviceLocatorException [" + serviceLocatorExceptionClass.getName() + "] is not a subclass of Exception");
- }
this.serviceLocatorExceptionConstructor =
determineServiceLocatorExceptionConstructor(serviceLocatorExceptionClass);
}
@@ -388,7 +385,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto
/**
* Check whether a service id was passed in.
*/
- private String tryGetBeanName(Object[] args) {
+ private String tryGetBeanName(@Nullable Object[] args) {
String beanName = "";
if (args != null && args.length == 1 && args[0] != null) {
beanName = args[0].toString();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java
index 906d639774..9c23fe38e2 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java
@@ -22,6 +22,7 @@ import java.util.Set;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.ResolvableType;
+import org.springframework.lang.Nullable;
/**
* Simple factory for shared Set instances. Allows for central setup
@@ -54,7 +55,7 @@ public class SetFactoryBean extends AbstractFactoryBean> {
* @see java.util.LinkedHashSet
*/
@SuppressWarnings("rawtypes")
- public void setTargetSetClass(Class extends Set> targetSetClass) {
+ public void setTargetSetClass(@Nullable Class extends Set> targetSetClass) {
if (targetSetClass == null) {
throw new IllegalArgumentException("'targetSetClass' must not be null");
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java
index 5d52fae329..4cae579140 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/SmartInstantiationAwareBeanPostProcessor.java
@@ -87,6 +87,7 @@ public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationA
* (typically with the passed-in bean instance as default)
* @throws org.springframework.beans.BeansException in case of errors
*/
+ @Nullable
default Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
return bean;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java
index 118b592060..303de9c8b3 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java
@@ -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.
@@ -130,6 +130,7 @@ public class TypedStringValue implements BeanMetadataElement {
/**
* Return the type to convert to.
*/
+ @Nullable
public String getTargetTypeName() {
Object targetTypeValue = this.targetType;
if (targetTypeValue instanceof Class) {
@@ -157,10 +158,11 @@ public class TypedStringValue implements BeanMetadataElement {
*/
@Nullable
public Class> resolveTargetType(ClassLoader classLoader) throws ClassNotFoundException {
- if (this.targetType == null) {
+ String typeName = getTargetTypeName();
+ if (typeName == null) {
return null;
}
- Class> resolvedClass = ClassUtils.forName(getTargetTypeName(), classLoader);
+ Class> resolvedClass = ClassUtils.forName(typeName, classLoader);
this.targetType = resolvedClass;
return resolvedClass;
}
@@ -170,7 +172,7 @@ public class TypedStringValue implements BeanMetadataElement {
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java
index 53b857274c..299ae7bd6d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java
@@ -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.
@@ -19,6 +19,7 @@ package org.springframework.beans.factory.parsing;
import java.util.LinkedList;
import java.util.List;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -44,7 +45,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition {
* @param name the name of the composite component
* @param source the source element that defines the root of the composite component
*/
- public CompositeComponentDefinition(String name, Object source) {
+ public CompositeComponentDefinition(String name, @Nullable Object source) {
Assert.notNull(name, "Name must not be null");
this.name = name;
this.source = source;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java
index fdab1473e0..848af16779 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ImportDefinition.java
@@ -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.
@@ -59,7 +59,7 @@ public class ImportDefinition implements BeanMetadataElement {
* @param importedResource the location of the imported resource
* @param source the source object (may be {@code null})
*/
- public ImportDefinition(String importedResource, Resource[] actualResources, @Nullable Object source) {
+ public ImportDefinition(String importedResource, @Nullable Resource[] actualResources, @Nullable Object source) {
Assert.notNull(importedResource, "Imported resource must not be null");
this.importedResource = importedResource;
this.actualResources = actualResources;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
index 19e9333b12..454fe135dc 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
@@ -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.
@@ -52,53 +52,53 @@ public class ReaderContext {
}
- public void fatal(String message, Object source) {
+ public void fatal(String message, @Nullable Object source) {
fatal(message, source, null, null);
}
- public void fatal(String message, Object source, Throwable ex) {
- fatal(message, source, null, ex);
+ public void fatal(String message, @Nullable Object source, @Nullable Throwable cause) {
+ fatal(message, source, null, cause);
}
- public void fatal(String message, Object source, @Nullable ParseState parseState) {
+ public void fatal(String message, @Nullable Object source, @Nullable ParseState parseState) {
fatal(message, source, parseState, null);
}
- public void fatal(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
+ public void fatal(String message, @Nullable Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.fatal(new Problem(message, location, parseState, cause));
}
- public void error(String message, Object source) {
+ public void error(String message, @Nullable Object source) {
error(message, source, null, null);
}
- public void error(String message, Object source, @Nullable Throwable ex) {
- error(message, source, null, ex);
+ public void error(String message, @Nullable Object source, @Nullable Throwable cause) {
+ error(message, source, null, cause);
}
- public void error(String message, Object source, @Nullable ParseState parseState) {
+ public void error(String message, @Nullable Object source, @Nullable ParseState parseState) {
error(message, source, parseState, null);
}
- public void error(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
+ public void error(String message, @Nullable Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.error(new Problem(message, location, parseState, cause));
}
- public void warning(String message, Object source) {
+ public void warning(String message, @Nullable Object source) {
warning(message, source, null, null);
}
- public void warning(String message, Object source, @Nullable Throwable ex) {
- warning(message, source, null, ex);
+ public void warning(String message, @Nullable Object source, @Nullable Throwable cause) {
+ warning(message, source, null, cause);
}
- public void warning(String message, Object source, @Nullable ParseState parseState) {
+ public void warning(String message, @Nullable Object source, @Nullable ParseState parseState) {
warning(message, source, parseState, null);
}
- public void warning(String message, Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
+ public void warning(String message, @Nullable Object source, @Nullable ParseState parseState, @Nullable Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.warning(new Problem(message, location, parseState, cause));
}
@@ -112,15 +112,15 @@ public class ReaderContext {
this.eventListener.componentRegistered(componentDefinition);
}
- public void fireAliasRegistered(String beanName, String alias, Object source) {
+ public void fireAliasRegistered(String beanName, String alias, @Nullable Object source) {
this.eventListener.aliasRegistered(new AliasDefinition(beanName, alias, source));
}
- public void fireImportProcessed(String importedResource, Object source) {
+ public void fireImportProcessed(String importedResource, @Nullable Object source) {
this.eventListener.importProcessed(new ImportDefinition(importedResource, source));
}
- public void fireImportProcessed(String importedResource, Resource[] actualResources, Object source) {
+ public void fireImportProcessed(String importedResource, Resource[] actualResources, @Nullable Object source) {
this.eventListener.importProcessed(new ImportDefinition(importedResource, actualResources, source));
}
@@ -129,6 +129,7 @@ public class ReaderContext {
return this.sourceExtractor;
}
+ @Nullable
public Object extractSource(Object sourceCandidate) {
return this.sourceExtractor.extractSource(sourceCandidate, this.resource);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
index 19a6f971fd..32b259e489 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
@@ -59,7 +59,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -78,6 +77,7 @@ import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.ResolvableType;
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;
@@ -203,7 +203,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* names if needed (e.g. for constructor names).
*
Default is a {@link DefaultParameterNameDiscoverer}.
*/
- public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) {
+ public void setParameterNameDiscoverer(@Nullable ParameterNameDiscoverer parameterNameDiscoverer) {
this.parameterNameDiscoverer = parameterNameDiscoverer;
}
@@ -211,6 +211,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* Return the ParameterNameDiscoverer to use for resolving method parameter
* names if needed.
*/
+ @Nullable
protected ParameterNameDiscoverer getParameterNameDiscoverer() {
return this.parameterNameDiscoverer;
}
@@ -320,10 +321,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
RootBeanDefinition rbd = (RootBeanDefinition) mbd;
bd = (rbd.isPrototype() ? rbd : rbd.cloneBeanDefinition());
}
- if (!mbd.isPrototype()) {
- if (bd == null) {
- bd = new RootBeanDefinition(mbd);
- }
+ if (bd == null) {
+ bd = new RootBeanDefinition(mbd);
+ }
+ if (!bd.isPrototype()) {
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bd.allowCaching = ClassUtils.isCacheSafe(ClassUtils.getUserClass(existingBean), getBeanClassLoader());
}
@@ -363,12 +364,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
Object bean;
final BeanFactory parent = this;
if (System.getSecurityManager() != null) {
- bean = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- return getInstantiationStrategy().instantiate(bd, null, parent);
- }
- }, getAccessControlContext());
+ bean = AccessController.doPrivileged((PrivilegedAction) () ->
+ getInstantiationStrategy().instantiate(bd, null, parent),
+ getAccessControlContext());
}
else {
bean = getInstantiationStrategy().instantiate(bd, null, parent);
@@ -416,7 +414,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
result = beanProcessor.postProcessBeforeInitialization(result, beanName);
if (result == null) {
- return result;
+ return null;
}
}
return result;
@@ -430,7 +428,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) {
result = beanProcessor.postProcessAfterInitialization(result, beanName);
if (result == null) {
- return result;
+ return null;
}
}
return result;
@@ -452,7 +450,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #doCreateBean
*/
@Override
- protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) throws BeanCreationException {
+ protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
+ throws BeanCreationException {
+
if (logger.isDebugEnabled()) {
logger.debug("Creating instance of bean '" + beanName + "'");
}
@@ -523,7 +523,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #instantiateUsingFactoryMethod
* @see #autowireConstructor
*/
- protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args)
+ @Nullable
+ protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final @Nullable Object[] args)
throws BeanCreationException {
// Instantiate the bean.
@@ -538,17 +539,19 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
Class> beanType = (instanceWrapper != null ? instanceWrapper.getWrappedClass() : null);
mbd.resolvedTargetType = beanType;
- // Allow post-processors to modify the merged bean definition.
- synchronized (mbd.postProcessingLock) {
- if (!mbd.postProcessed) {
- try {
- applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
+ if (beanType != null) {
+ // Allow post-processors to modify the merged bean definition.
+ synchronized (mbd.postProcessingLock) {
+ if (!mbd.postProcessed) {
+ try {
+ applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
+ }
+ catch (Throwable ex) {
+ throw new BeanCreationException(mbd.getResourceDescription(), beanName,
+ "Post-processing of merged bean definition failed", ex);
+ }
+ mbd.postProcessed = true;
}
- catch (Throwable ex) {
- throw new BeanCreationException(mbd.getResourceDescription(), beanName,
- "Post-processing of merged bean definition failed", ex);
- }
- mbd.postProcessed = true;
}
}
@@ -561,12 +564,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
logger.debug("Eagerly caching bean '" + beanName +
"' to allow for resolving potential circular references");
}
- addSingletonFactory(beanName, new ObjectFactory() {
- @Override
- public Object getObject() throws BeansException {
- return getEarlyBeanReference(beanName, mbd, bean);
- }
- });
+ addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));
}
// Initialize the bean instance.
@@ -614,13 +612,15 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
}
- // Register bean as disposable.
- try {
- registerDisposableBeanIfNecessary(beanName, bean, mbd);
- }
- catch (BeanDefinitionValidationException ex) {
- throw new BeanCreationException(
- mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
+ if (bean != null) {
+ // Register bean as disposable.
+ try {
+ registerDisposableBeanIfNecessary(beanName, bean, mbd);
+ }
+ catch (BeanDefinitionValidationException ex) {
+ throw new BeanCreationException(
+ mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
+ }
}
return exposedObject;
@@ -898,7 +898,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @return the object to expose as bean reference
*/
@Nullable
- protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, Object bean) {
+ protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, @Nullable Object bean) {
Object exposedObject = bean;
if (bean != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
for (BeanPostProcessor bp : getBeanPostProcessors()) {
@@ -947,6 +947,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
instance = resolveBeforeInstantiation(beanName, mbd);
if (instance == null) {
bw = createBeanInstance(beanName, mbd, null);
+ if (bw == null) {
+ return null;
+ }
instance = bw.getWrappedInstance();
}
}
@@ -985,6 +988,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
instance = resolveBeforeInstantiation(beanName, mbd);
if (instance == null) {
BeanWrapper bw = createBeanInstance(beanName, mbd, null);
+ if (bw == null) {
+ return null;
+ }
instance = bw.getWrappedInstance();
}
}
@@ -1084,6 +1090,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #autowireConstructor
* @see #instantiateBean
*/
+ @Nullable
protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) {
// Make sure bean class is actually resolved at this point.
Class> beanClass = resolveBeanClass(mbd, beanName);
@@ -1171,7 +1178,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
*/
@Override
protected Object getObjectForBeanInstance(
- Object beanInstance, String name, String beanName, RootBeanDefinition mbd) {
+ @Nullable Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) {
String currentlyCreatedBean = this.currentlyCreatedBean.get();
if (currentlyCreatedBean != null) {
@@ -1191,7 +1198,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor#determineCandidateConstructors
*/
@Nullable
- protected Constructor>[] determineConstructorsFromBeanPostProcessors(Class> beanClass, String beanName)
+ protected Constructor>[] determineConstructorsFromBeanPostProcessors(@Nullable Class> beanClass, String beanName)
throws BeansException {
if (beanClass != null && hasInstantiationAwareBeanPostProcessors()) {
@@ -1219,12 +1226,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
Object beanInstance;
final BeanFactory parent = this;
if (System.getSecurityManager() != null) {
- beanInstance = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- return getInstantiationStrategy().instantiate(mbd, beanName, parent);
- }
- }, getAccessControlContext());
+ beanInstance = AccessController.doPrivileged((PrivilegedAction) () ->
+ getInstantiationStrategy().instantiate(mbd, beanName, parent),
+ getAccessControlContext());
}
else {
beanInstance = getInstantiationStrategy().instantiate(mbd, beanName, parent);
@@ -1250,6 +1254,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @return a BeanWrapper for the new instance
* @see #getBean(String, Object[])
*/
+ @Nullable
protected BeanWrapper instantiateUsingFactoryMethod(
String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) {
@@ -1283,7 +1288,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @param mbd the bean definition for the bean
* @param bw BeanWrapper with bean instance
*/
- protected void populateBean(String beanName, RootBeanDefinition mbd, BeanWrapper bw) {
+ protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) {
PropertyValues pvs = mbd.getPropertyValues();
if (bw == null) {
@@ -1420,7 +1425,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if (Object.class != pd.getPropertyType()) {
MethodParameter methodParam = BeanUtils.getWriteMethodParameter(pd);
// Do not allow eager init for type matching in case of a prioritized post-processor.
- boolean eager = !PriorityOrdered.class.isAssignableFrom(bw.getWrappedClass());
+ boolean eager = !PriorityOrdered.class.isInstance(bw.getWrappedInstance());
DependencyDescriptor desc = new AutowireByTypeDependencyDescriptor(methodParam, eager);
Object autowiredArgument = resolveDependency(desc, beanName, autowiredBeanNames, converter);
if (autowiredArgument != null) {
@@ -1655,6 +1660,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
/**
* Convert the given value for the specified target property.
*/
+ @Nullable
private Object convertForProperty(Object value, String propertyName, BeanWrapper bw, TypeConverter converter) {
if (converter instanceof BeanWrapperImpl) {
return ((BeanWrapperImpl) converter).convertForProperty(value, propertyName);
@@ -1684,14 +1690,12 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #invokeInitMethods
* @see #applyBeanPostProcessorsAfterInitialization
*/
+ @Nullable
protected Object initializeBean(final String beanName, final Object bean, @Nullable RootBeanDefinition mbd) {
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- invokeAwareMethods(beanName, bean);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ invokeAwareMethods(beanName, bean);
+ return null;
}, getAccessControlContext());
}
else {
@@ -1703,18 +1707,20 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
wrappedBean = applyBeanPostProcessorsBeforeInitialization(wrappedBean, beanName);
}
- try {
- invokeInitMethods(beanName, wrappedBean, mbd);
- }
- catch (Throwable ex) {
- throw new BeanCreationException(
- (mbd != null ? mbd.getResourceDescription() : null),
- beanName, "Invocation of init method failed", ex);
+ if (wrappedBean != null) {
+ try {
+ invokeInitMethods(beanName, wrappedBean, mbd);
+ }
+ catch (Throwable ex) {
+ throw new BeanCreationException(
+ (mbd != null ? mbd.getResourceDescription() : null),
+ beanName, "Invocation of init method failed", ex);
+ }
+ if (mbd == null || !mbd.isSynthetic()) {
+ wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
+ }
}
- if (mbd == null || !mbd.isSynthetic()) {
- wrappedBean = applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);
- }
return wrappedBean;
}
@@ -1754,12 +1760,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
if (System.getSecurityManager() != null) {
try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- ((InitializingBean) bean).afterPropertiesSet();
- return null;
- }
+ AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
+ ((InitializingBean) bean).afterPropertiesSet();
+ return null;
}, getAccessControlContext());
}
catch (PrivilegedActionException pae) {
@@ -1791,9 +1794,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
throws Throwable {
String initMethodName = mbd.getInitMethodName();
+ Assert.state(initMethodName != null, "No init method set");
final Method initMethod = (mbd.isNonPublicAccessAllowed() ?
BeanUtils.findMethod(bean.getClass(), initMethodName) :
ClassUtils.getMethodIfAvailable(bean.getClass(), initMethodName));
+
if (initMethod == null) {
if (mbd.isEnforceInitMethod()) {
throw new BeanDefinitionValidationException("Couldn't find an init method named '" +
@@ -1814,21 +1819,13 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- ReflectionUtils.makeAccessible(initMethod);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(initMethod);
+ return null;
});
try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- initMethod.invoke(bean);
- return null;
- }
- }, getAccessControlContext());
+ AccessController.doPrivileged((PrivilegedExceptionAction) () ->
+ initMethod.invoke(bean), getAccessControlContext());
}
catch (PrivilegedActionException pae) {
InvocationTargetException ex = (InvocationTargetException) pae.getException();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
index 5cdab4336d..94e169e391 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
@@ -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.
@@ -201,7 +201,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Create a new AbstractBeanDefinition with the given
* constructor argument values and property values.
*/
- protected AbstractBeanDefinition(ConstructorArgumentValues cargs, MutablePropertyValues pvs) {
+ protected AbstractBeanDefinition(@Nullable ConstructorArgumentValues cargs, @Nullable MutablePropertyValues pvs) {
setConstructorArgumentValues(cargs);
setPropertyValues(pvs);
}
@@ -340,7 +340,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Specify the bean class name of this bean definition.
*/
@Override
- public void setBeanClassName(String beanClassName) {
+ public void setBeanClassName(@Nullable String beanClassName) {
this.beanClass = beanClassName;
}
@@ -361,7 +361,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify the class for this bean.
*/
- public void setBeanClass(Class> beanClass) {
+ public void setBeanClass(@Nullable Class> beanClass) {
this.beanClass = beanClass;
}
@@ -371,7 +371,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @throws IllegalStateException if the bean definition does not define a bean class,
* or a specified bean class name has not been resolved into an actual Class
*/
- @Nullable
public Class> getBeanClass() throws IllegalStateException {
Object beanClassObject = this.beanClass;
if (beanClassObject == null) {
@@ -399,6 +398,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @return the resolved bean class
* @throws ClassNotFoundException if the class name could be resolved
*/
+ @Nullable
public Class> resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundException {
String className = getBeanClassName();
if (className == null) {
@@ -420,7 +420,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #SCOPE_PROTOTYPE
*/
@Override
- public void setScope(String scope) {
+ public void setScope(@Nullable String scope) {
this.scope = scope;
}
@@ -566,7 +566,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* of dependencies like statics (*ugh*) or database preparation on startup.
*/
@Override
- public void setDependsOn(String... dependsOn) {
+ public void setDependsOn(@Nullable String... dependsOn) {
this.dependsOn = dependsOn;
}
@@ -637,6 +637,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Return the qualifier mapped to the provided type name.
*/
+ @Nullable
public AutowireCandidateQualifier getQualifier(String typeName) {
return this.qualifiers.get(typeName);
}
@@ -668,7 +669,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #setConstructorArgumentValues(ConstructorArgumentValues)
* @see #setPropertyValues(MutablePropertyValues)
*/
- public void setInstanceSupplier(Supplier> instanceSupplier) {
+ public void setInstanceSupplier(@Nullable Supplier> instanceSupplier) {
this.instanceSupplier = instanceSupplier;
}
@@ -726,7 +727,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #setFactoryMethodName
*/
@Override
- public void setFactoryBeanName(String factoryBeanName) {
+ public void setFactoryBeanName(@Nullable String factoryBeanName) {
this.factoryBeanName = factoryBeanName;
}
@@ -747,7 +748,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #setBeanClassName
*/
@Override
- public void setFactoryMethodName(String factoryMethodName) {
+ public void setFactoryMethodName(@Nullable String factoryMethodName) {
this.factoryMethodName = factoryMethodName;
}
@@ -762,7 +763,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify constructor argument values for this bean.
*/
- public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues) {
+ public void setConstructorArgumentValues(@Nullable ConstructorArgumentValues constructorArgumentValues) {
this.constructorArgumentValues =
(constructorArgumentValues != null ? constructorArgumentValues : new ConstructorArgumentValues());
}
@@ -785,7 +786,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify property values for this bean, if any.
*/
- public void setPropertyValues(MutablePropertyValues propertyValues) {
+ public void setPropertyValues(@Nullable MutablePropertyValues propertyValues) {
this.propertyValues = (propertyValues != null ? propertyValues : new MutablePropertyValues());
}
@@ -800,24 +801,24 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify method overrides for the bean, if any.
*/
- public void setMethodOverrides(MethodOverrides methodOverrides) {
+ public void setMethodOverrides(@Nullable MethodOverrides methodOverrides) {
this.methodOverrides = (methodOverrides != null ? methodOverrides : new MethodOverrides());
}
/**
* Return information about methods to be overridden by the IoC
* container. This will be empty if there are no method overrides.
- * Never returns {@code null}.
+ * Never returns {@code null}.
*/
public MethodOverrides getMethodOverrides() {
return this.methodOverrides;
}
/**
- * Set the name of the initializer method. The default is {@code null}
- * in which case there is no initializer method.
+ * Set the name of the initializer method.
+ *
The default is {@code null} in which case there is no initializer method.
*/
- public void setInitMethodName(String initMethodName) {
+ public void setInitMethodName(@Nullable String initMethodName) {
this.initMethodName = initMethodName;
}
@@ -831,7 +832,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify whether or not the configured init method is the default.
- * Default value is {@code false}.
+ *
The default value is {@code false}.
* @see #setInitMethodName
*/
public void setEnforceInitMethod(boolean enforceInitMethod) {
@@ -847,10 +848,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
}
/**
- * Set the name of the destroy method. The default is {@code null}
- * in which case there is no destroy method.
+ * Set the name of the destroy method.
+ *
The default is {@code null} in which case there is no destroy method.
*/
- public void setDestroyMethodName(String destroyMethodName) {
+ public void setDestroyMethodName(@Nullable String destroyMethodName) {
this.destroyMethodName = destroyMethodName;
}
@@ -864,7 +865,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Specify whether or not the configured destroy method is the default.
- * Default value is {@code false}.
+ *
The default value is {@code false}.
* @see #setDestroyMethodName
*/
public void setEnforceDestroyMethod(boolean enforceDestroyMethod) {
@@ -914,7 +915,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Set a human-readable description of this bean definition.
*/
- public void setDescription(String description) {
+ public void setDescription(@Nullable String description) {
this.description = description;
}
@@ -945,8 +946,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Set a description of the resource that this bean definition
* came from (for the purpose of showing context in case of errors).
*/
- public void setResourceDescription(String resourceDescription) {
- this.resource = new DescriptiveResource(resourceDescription);
+ public void setResourceDescription(@Nullable String resourceDescription) {
+ this.resource = (resourceDescription != null ? new DescriptiveResource(resourceDescription) : null);
}
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java
index a935bdbe26..bacd7c062f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java
@@ -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.
@@ -151,6 +151,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
* should be read and which should be omitted.
*/
public void setEnvironment(Environment environment) {
+ Assert.notNull(environment, "Environment must not be null");
this.environment = environment;
}
@@ -164,7 +165,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
* (without explicit bean name specified).
*
Default is a {@link DefaultBeanNameGenerator}.
*/
- public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
+ public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) {
this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : new DefaultBeanNameGenerator());
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
index 30947b473b..5e50772e82 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
@@ -213,7 +213,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @return an instance of the bean
* @throws BeansException if the bean could not be created
*/
- public T getBean(String name, Class requiredType, Object... args) throws BeansException {
+ public T getBean(String name, @Nullable Class requiredType, @Nullable Object... args)
+ throws BeansException {
+
return doGetBean(name, requiredType, args, false);
}
@@ -229,9 +231,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @throws BeansException if the bean could not be created
*/
@SuppressWarnings("unchecked")
- protected T doGetBean(
- final String name, @Nullable final Class requiredType, @Nullable final Object[] args, boolean typeCheckOnly)
- throws BeansException {
+ protected T doGetBean(final String name, @Nullable final Class requiredType,
+ @Nullable final Object[] args, boolean typeCheckOnly) throws BeansException {
final String beanName = transformedBeanName(name);
Object bean;
@@ -263,7 +264,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
// Not found -> check parent.
String nameToLookup = originalBeanName(name);
- if (args != null) {
+ if (parentBeanFactory instanceof AbstractBeanFactory) {
+ return ((AbstractBeanFactory) parentBeanFactory).doGetBean(
+ nameToLookup, requiredType, args, typeCheckOnly);
+ }
+ else if (args != null) {
// Delegation to parent with explicit args.
return (T) parentBeanFactory.getBean(nameToLookup, args);
}
@@ -296,19 +301,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Create bean instance.
if (mbd.isSingleton()) {
- sharedInstance = getSingleton(beanName, new ObjectFactory() {
- @Override
- public Object getObject() throws BeansException {
- try {
- return createBean(beanName, mbd, args);
- }
- catch (BeansException ex) {
- // Explicitly remove instance from singleton cache: It might have been put there
- // eagerly by the creation process, to allow for circular reference resolution.
- // Also remove any beans that received a temporary reference to the bean.
- destroySingleton(beanName);
- throw ex;
- }
+ sharedInstance = getSingleton(beanName, () -> {
+ try {
+ return createBean(beanName, mbd, args);
+ }
+ catch (BeansException ex) {
+ // Explicitly remove instance from singleton cache: It might have been put there
+ // eagerly by the creation process, to allow for circular reference resolution.
+ // Also remove any beans that received a temporary reference to the bean.
+ destroySingleton(beanName);
+ throw ex;
}
});
bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
@@ -363,7 +365,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
// Check if required type matches the type of the actual bean instance.
- if (requiredType != null && bean != null && !requiredType.isAssignableFrom(bean.getClass())) {
+ if (requiredType != null && bean != null && !requiredType.isInstance(bean)) {
try {
return getTypeConverter().convertIfNecessary(bean, requiredType);
}
@@ -457,13 +459,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
if (isFactoryBean(beanName, mbd)) {
final FactoryBean> fb = (FactoryBean>) getBean(FACTORY_BEAN_PREFIX + beanName);
if (System.getSecurityManager() != null) {
- return AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Boolean run() {
- return ((fb instanceof SmartFactoryBean && ((SmartFactoryBean>) fb).isPrototype()) ||
- !fb.isSingleton());
- }
- }, getAccessControlContext());
+ return AccessController.doPrivileged((PrivilegedAction) () ->
+ ((fb instanceof SmartFactoryBean && ((SmartFactoryBean>) fb).isPrototype()) || !fb.isSingleton()),
+ getAccessControlContext());
}
else {
return ((fb instanceof SmartFactoryBean && ((SmartFactoryBean>) fb).isPrototype()) ||
@@ -579,7 +577,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
- public boolean isTypeMatch(String name, Class> typeToMatch) throws NoSuchBeanDefinitionException {
+ public boolean isTypeMatch(String name, @Nullable Class> typeToMatch) throws NoSuchBeanDefinitionException {
return isTypeMatch(name, ResolvableType.forRawClass(typeToMatch));
}
@@ -690,7 +688,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
//---------------------------------------------------------------------
@Override
- public void setParentBeanFactory(BeanFactory parentBeanFactory) {
+ public void setParentBeanFactory(@Nullable BeanFactory parentBeanFactory) {
if (this.parentBeanFactory != null && this.parentBeanFactory != parentBeanFactory) {
throw new IllegalStateException("Already associated with parent BeanFactory: " + this.parentBeanFactory);
}
@@ -728,7 +726,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
- public void setBeanExpressionResolver(BeanExpressionResolver resolver) {
+ public void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver) {
this.beanExpressionResolver = resolver;
}
@@ -738,7 +736,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
- public void setConversionService(ConversionService conversionService) {
+ public void setConversionService(@Nullable ConversionService conversionService) {
this.conversionService = conversionService;
}
@@ -820,7 +818,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
- public String resolveEmbeddedValue(String value) {
+ public String resolveEmbeddedValue(@Nullable String value) {
if (value == null) {
return null;
}
@@ -1365,12 +1363,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
return mbd.getBeanClass();
}
if (System.getSecurityManager() != null) {
- return AccessController.doPrivileged(new PrivilegedExceptionAction>() {
- @Override
- public Class> run() throws Exception {
- return doResolveBeanClass(mbd, typesToMatch);
- }
- }, getAccessControlContext());
+ return AccessController.doPrivileged((PrivilegedExceptionAction>) () ->
+ doResolveBeanClass(mbd, typesToMatch), getAccessControlContext());
}
else {
return doResolveBeanClass(mbd, typesToMatch);
@@ -1388,6 +1382,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
}
+ @Nullable
private Class> doResolveBeanClass(RootBeanDefinition mbd, Class>... typesToMatch)
throws ClassNotFoundException {
@@ -1439,11 +1434,19 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @return the resolved value
* @see #setBeanExpressionResolver
*/
- protected Object evaluateBeanDefinitionString(String value, BeanDefinition beanDefinition) {
+ @Nullable
+ protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) {
if (this.beanExpressionResolver == null) {
return value;
}
- Scope scope = (beanDefinition != null ? getRegisteredScope(beanDefinition.getScope()) : null);
+
+ Scope scope = null;
+ if (beanDefinition != null) {
+ String scopeName = beanDefinition.getScope();
+ if (scopeName != null) {
+ scope = getRegisteredScope(scopeName);
+ }
+ }
return this.beanExpressionResolver.evaluate(value, new BeanExpressionContext(this, scope));
}
@@ -1605,8 +1608,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @param mbd the merged bean definition
* @return the object to expose for the bean
*/
+ @Nullable
protected Object getObjectForBeanInstance(
- Object beanInstance, String name, String beanName, RootBeanDefinition mbd) {
+ @Nullable Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) {
+
+ if (beanInstance == null) {
+ return null;
+ }
// Don't let calling code try to dereference the factory if the bean isn't a factory.
if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) {
@@ -1657,7 +1665,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @see AbstractBeanDefinition#getDestroyMethodName()
* @see org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
*/
- protected boolean requiresDestruction(Object bean, RootBeanDefinition mbd) {
+ protected boolean requiresDestruction(@Nullable Object bean, RootBeanDefinition mbd) {
return (bean != null &&
(DisposableBeanAdapter.hasDestroyMethod(bean, mbd) || (hasDestructionAwareBeanPostProcessors() &&
DisposableBeanAdapter.hasApplicableProcessors(bean, getBeanPostProcessors()))));
@@ -1738,7 +1746,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @see ChildBeanDefinition
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#getBeanDefinition
*/
- protected abstract BeanDefinition getBeanDefinition(@Nullable String beanName) throws BeansException;
+ protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException;
/**
* Create a bean instance for the given merged bean definition (and arguments).
@@ -1751,7 +1759,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* @return a new instance of the bean
* @throws BeanCreationException if the bean could not be created
*/
- protected abstract Object createBean(String beanName, RootBeanDefinition mbd, Object[] args)
+ @Nullable
+ protected abstract Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
throws BeanCreationException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java
index 37ef03304d..60afe0a0f1 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireCandidateResolver.java
@@ -81,7 +81,7 @@ public interface AutowireCandidateResolver {
* @since 4.0
*/
@Nullable
- default Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, String beanName) {
+ default Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) {
return null;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java
index aa0f48ab99..f6e29cad61 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java
@@ -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 java.util.Set;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.TypedStringValue;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -144,6 +145,7 @@ abstract class AutowireUtils {
* @param requiredType the type to assign the result to
* @return the resolved value
*/
+ @Nullable
public static Object resolveAutowiringValue(Object autowiringValue, Class> requiredType) {
if (autowiringValue instanceof ObjectFactory && !requiredType.isInstance(autowiringValue)) {
ObjectFactory> factory = (ObjectFactory>) autowiringValue;
@@ -220,15 +222,18 @@ abstract class AutowireUtils {
return typedValue.getTargetType();
}
try {
- return typedValue.resolveTargetType(classLoader);
+ Class> resolvedType = typedValue.resolveTargetType(classLoader);
+ if (resolvedType != null) {
+ return resolvedType;
+ }
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException("Failed to resolve value type [" +
typedValue.getTargetTypeName() + "] for factory method argument", ex);
}
}
- // Only consider argument type if it is a simple value...
- if (arg != null && !(arg instanceof BeanMetadataElement)) {
+ else if (arg != null && !(arg instanceof BeanMetadataElement)) {
+ // Only consider argument type if it is a simple value...
return arg.getClass();
}
return method.getReturnType();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java
index 9337d13e86..75b37718ec 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java
@@ -73,7 +73,9 @@ public class BeanDefinitionBuilder {
* @param instanceSupplier a callback for creating an instance of the bean
* @since 5.0
*/
- public static BeanDefinitionBuilder genericBeanDefinition(Class beanClass, Supplier instanceSupplier) {
+ public static BeanDefinitionBuilder genericBeanDefinition(
+ @Nullable Class beanClass, Supplier instanceSupplier) {
+
BeanDefinitionBuilder builder = new BeanDefinitionBuilder();
builder.beanDefinition = new GenericBeanDefinition();
builder.beanDefinition.setBeanClass(beanClass);
@@ -321,10 +323,8 @@ public class BeanDefinitionBuilder {
* @since 5.0
*/
public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers) {
- if (customizers != null) {
- for (BeanDefinitionCustomizer customizer : customizers) {
- customizer.customize(beanDefinition);
- }
+ for (BeanDefinitionCustomizer customizer : customizers) {
+ customizer.customize(beanDefinition);
}
return this;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
index db7ccda800..3a095939ed 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.beans.factory.support;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -61,18 +62,20 @@ public class BeanDefinitionDefaults {
return this.autowireMode;
}
- public void setInitMethodName(String initMethodName) {
- this.initMethodName = (StringUtils.hasText(initMethodName)) ? initMethodName : null;
+ public void setInitMethodName(@Nullable String initMethodName) {
+ this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
}
+ @Nullable
public String getInitMethodName() {
return this.initMethodName;
}
- public void setDestroyMethodName(String destroyMethodName) {
- this.destroyMethodName = (StringUtils.hasText(destroyMethodName)) ? destroyMethodName : null;
+ public void setDestroyMethodName(@Nullable String destroyMethodName) {
+ this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);
}
+ @Nullable
public String getDestroyMethodName() {
return this.destroyMethodName;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java
index e14a7dc483..4318050337 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +50,8 @@ public interface BeanDefinitionReader {
* Return the resource loader to use for resource locations.
* Can be checked for the ResourcePatternResolver interface and cast
* accordingly, for loading multiple resources for a given resource pattern.
- * Null suggests that absolute resource loading is not available
- * for this bean definition reader.
+ *
A {@code null} return value suggests that absolute resource loading
+ * is not available for this bean definition reader.
*
This is mainly meant to be used for importing further resources
* from within a bean definition resource, for example via the "import"
* tag in XML bean definitions. It is recommended, however, to apply
@@ -63,6 +63,7 @@ public interface BeanDefinitionReader {
* @see #loadBeanDefinitions(String)
* @see org.springframework.core.io.support.ResourcePatternResolver
*/
+ @Nullable
ResourceLoader getResourceLoader();
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionRegistry.java
index ba96f93dcb..7424851403 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionRegistry.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionRegistry.java
@@ -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.
@@ -75,7 +75,7 @@ public interface BeanDefinitionRegistry extends AliasRegistry {
* @return the BeanDefinition for the given name (never {@code null})
* @throws NoSuchBeanDefinitionException if there is no such bean definition
*/
- BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException;
+ BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
/**
* Check if this registry contains a bean definition with the given name.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java
index 7d60ad437b..26f0c41062 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -101,6 +101,7 @@ class BeanDefinitionValueResolver {
* @param value the value object to resolve
* @return the resolved object
*/
+ @Nullable
public Object resolveValueIfNecessary(Object argName, @Nullable Object value) {
// We must check each value to see whether it requires a runtime reference
// to another bean to be resolved.
@@ -177,6 +178,11 @@ class BeanDefinitionValueResolver {
if (propValue instanceof TypedStringValue) {
propValue = evaluate((TypedStringValue) propValue);
}
+ if (propKey == null || propValue == null) {
+ throw new BeanCreationException(
+ this.beanDefinition.getResourceDescription(), this.beanName,
+ "Error converting Properties key/value pair for " + argName + ": resolved to null");
+ }
copy.put(propKey, propValue);
}
return copy;
@@ -211,6 +217,7 @@ class BeanDefinitionValueResolver {
* @param value the candidate value (may be an expression)
* @return the resolved value
*/
+ @Nullable
protected Object evaluate(TypedStringValue value) {
Object result = doEvaluate(value.getValue());
if (!ObjectUtils.nullSafeEquals(result, value.getValue())) {
@@ -224,7 +231,8 @@ class BeanDefinitionValueResolver {
* @param value the original value (may be an expression)
* @return the resolved value if necessary, or the original value
*/
- protected Object evaluate(Object value) {
+ @Nullable
+ protected Object evaluate(@Nullable Object value) {
if (value instanceof String) {
return doEvaluate((String) value);
}
@@ -252,7 +260,8 @@ class BeanDefinitionValueResolver {
* @param value the original value (may be an expression)
* @return the resolved value if necessary, or the original String value
*/
- private Object doEvaluate(String value) {
+ @Nullable
+ private Object doEvaluate(@Nullable String value) {
return this.beanFactory.evaluateBeanDefinitionString(value, this.beanDefinition);
}
@@ -278,6 +287,7 @@ class BeanDefinitionValueResolver {
* @param innerBd the bean definition for the inner bean
* @return the resolved inner bean instance
*/
+ @Nullable
private Object resolveInnerBean(Object argName, String innerBeanName, BeanDefinition innerBd) {
RootBeanDefinition mbd = null;
try {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java
index 62753396d0..7db4a69678 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java
@@ -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.
@@ -37,6 +37,7 @@ import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.cglib.proxy.NoOp;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -72,13 +73,13 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
@Override
- protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner) {
+ protected Object instantiateWithMethodInjection(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner) {
return instantiateWithMethodInjection(bd, beanName, owner, null);
}
@Override
- protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner,
- @Nullable Constructor> ctor, Object... args) {
+ protected Object instantiateWithMethodInjection(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
+ @Nullable Constructor> ctor, @Nullable Object... args) {
// Must generate CGLIB subclass...
return new CglibSubclassCreator(bd, owner).instantiate(ctor, args);
@@ -112,7 +113,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
* Ignored if the {@code ctor} parameter is {@code null}.
* @return new instance of the dynamically generated subclass
*/
- public Object instantiate(@Nullable Constructor> ctor, Object... args) {
+ public Object instantiate(@Nullable Constructor> ctor, @Nullable Object... args) {
Class> subclass = createEnhancedSubclass(this.beanDefinition);
Object instance;
if (ctor == null) {
@@ -195,7 +196,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
private final ClassLoader classLoader;
- public ClassLoaderAwareGeneratorStrategy(ClassLoader classLoader) {
+ public ClassLoaderAwareGeneratorStrategy(@Nullable ClassLoader classLoader) {
this.classLoader = classLoader;
}
@@ -281,12 +282,15 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable {
// Cast is safe, as CallbackFilter filters are used selectively.
LookupOverride lo = (LookupOverride) getBeanDefinition().getMethodOverrides().getOverride(method);
+ Assert.state(lo != null, "LookupOverride not found");
Object[] argsToUse = (args.length > 0 ? args : null); // if no-arg, don't insist on args at all
if (StringUtils.hasText(lo.getBeanName())) {
- return this.owner.getBean(lo.getBeanName(), argsToUse);
+ return (argsToUse != null ? this.owner.getBean(lo.getBeanName(), argsToUse) :
+ this.owner.getBean(lo.getBeanName()));
}
else {
- return this.owner.getBean(method.getReturnType(), argsToUse);
+ return (argsToUse != null ? this.owner.getBean(method.getReturnType(), argsToUse) :
+ this.owner.getBean(method.getReturnType()));
}
}
}
@@ -308,6 +312,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable {
ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method);
+ Assert.state(ro != null, "ReplaceOverride not found");
// TODO could cache if a singleton for minor performance optimization
MethodReplacer mr = this.owner.getBean(ro.getMethodReplacerBeanName(), MethodReplacer.class);
return mr.reimplement(obj, method, args);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
index 52767953fc..b48380d5af 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
@@ -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.
@@ -50,6 +50,7 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.NamedThreadLocal;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MethodInvoker;
import org.springframework.util.ObjectUtils;
@@ -255,22 +256,18 @@ class ConstructorResolver {
}
try {
+ final InstantiationStrategy strategy = beanFactory.getInstantiationStrategy();
Object beanInstance;
if (System.getSecurityManager() != null) {
final Constructor> ctorToUse = constructorToUse;
final Object[] argumentsToUse = argsToUse;
- beanInstance = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- return beanFactory.getInstantiationStrategy().instantiate(
- mbd, beanName, beanFactory, ctorToUse, argumentsToUse);
- }
- }, beanFactory.getAccessControlContext());
+ beanInstance = AccessController.doPrivileged((PrivilegedAction) () ->
+ strategy.instantiate(mbd, beanName, beanFactory, ctorToUse, argumentsToUse),
+ beanFactory.getAccessControlContext());
}
else {
- beanInstance = this.beanFactory.getInstantiationStrategy().instantiate(
- mbd, beanName, this.beanFactory, constructorToUse, argsToUse);
+ beanInstance = strategy.instantiate(mbd, beanName, this.beanFactory, constructorToUse, argsToUse);
}
bw.setBeanInstance(beanInstance);
@@ -298,6 +295,7 @@ class ConstructorResolver {
factoryClass = mbd.getBeanClass();
isStatic = true;
}
+ Assert.state(factoryClass != null, "Unresolvable factory class");
factoryClass = ClassUtils.getUserClass(factoryClass);
Method[] candidates = getCandidateMethods(factoryClass, mbd);
@@ -325,13 +323,9 @@ class ConstructorResolver {
*/
private Method[] getCandidateMethods(final Class> factoryClass, final RootBeanDefinition mbd) {
if (System.getSecurityManager() != null) {
- return AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Method[] run() {
- return (mbd.isNonPublicAccessAllowed() ?
- ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
- }
- });
+ return AccessController.doPrivileged((PrivilegedAction) () ->
+ (mbd.isNonPublicAccessAllowed() ?
+ ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods()));
}
else {
return (mbd.isNonPublicAccessAllowed() ?
@@ -372,10 +366,6 @@ class ConstructorResolver {
"factory-bean reference points back to the same bean definition");
}
factoryBean = this.beanFactory.getBean(factoryBeanName);
- if (factoryBean == null) {
- throw new BeanCreationException(mbd.getResourceDescription(), beanName,
- "factory-bean '" + factoryBeanName + "' (or a BeanPostProcessor involved) returned null");
- }
if (mbd.isSingleton() && this.beanFactory.containsSingleton(beanName)) {
throw new ImplicitlyAppearedSingletonException();
}
@@ -577,13 +567,9 @@ class ConstructorResolver {
final Object fb = factoryBean;
final Method factoryMethod = factoryMethodToUse;
final Object[] args = argsToUse;
- beanInstance = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- return beanFactory.getInstantiationStrategy().instantiate(
- mbd, beanName, beanFactory, fb, factoryMethod, args);
- }
- }, beanFactory.getAccessControlContext());
+ beanInstance = AccessController.doPrivileged((PrivilegedAction) () ->
+ beanFactory.getInstantiationStrategy().instantiate(mbd, beanName, beanFactory, fb, factoryMethod, args),
+ beanFactory.getAccessControlContext());
}
else {
beanInstance = this.beanFactory.getInstantiationStrategy().instantiate(
@@ -647,8 +633,8 @@ class ConstructorResolver {
else {
Object resolvedValue =
valueResolver.resolveValueIfNecessary("constructor argument", valueHolder.getValue());
- ConstructorArgumentValues.ValueHolder resolvedValueHolder =
- new ConstructorArgumentValues.ValueHolder(resolvedValue, valueHolder.getType(), valueHolder.getName());
+ ConstructorArgumentValues.ValueHolder resolvedValueHolder = new ConstructorArgumentValues.ValueHolder(
+ resolvedValue, valueHolder.getType(), valueHolder.getName());
resolvedValueHolder.setSource(valueHolder);
resolvedValues.addGenericArgumentValue(resolvedValueHolder);
}
@@ -663,15 +649,14 @@ class ConstructorResolver {
*/
private ArgumentsHolder createArgumentArray(
String beanName, RootBeanDefinition mbd, ConstructorArgumentValues resolvedValues,
- BeanWrapper bw, Class>[] paramTypes, String[] paramNames, Executable executable,
+ BeanWrapper bw, Class>[] paramTypes, @Nullable String[] paramNames, Executable executable,
boolean autowiring) throws UnsatisfiedDependencyException {
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
TypeConverter converter = (customConverter != null ? customConverter : bw);
ArgumentsHolder args = new ArgumentsHolder(paramTypes.length);
- Set usedValueHolders =
- new HashSet<>(paramTypes.length);
+ Set usedValueHolders = new HashSet<>(paramTypes.length);
Set autowiredBeanNames = new LinkedHashSet<>(4);
for (int paramIndex = 0; paramIndex < paramTypes.length; paramIndex++) {
@@ -697,31 +682,22 @@ class ConstructorResolver {
args.preparedArguments[paramIndex] = convertedValue;
}
else {
- ConstructorArgumentValues.ValueHolder sourceHolder =
- (ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
- Object sourceValue = sourceHolder.getValue();
MethodParameter methodParam = MethodParameter.forExecutable(executable, paramIndex);
try {
convertedValue = converter.convertIfNecessary(originalValue, paramType, methodParam);
- // TODO re-enable once race condition has been found (SPR-7423)
- /*
- if (originalValue == sourceValue || sourceValue instanceof TypedStringValue) {
- // Either a converted value or still the original one: store converted value.
- sourceHolder.setConvertedValue(convertedValue);
- args.preparedArguments[paramIndex] = convertedValue;
- }
- else {
- */
- args.resolveNecessary = true;
- args.preparedArguments[paramIndex] = sourceValue;
- // }
}
catch (TypeMismatchException ex) {
throw new UnsatisfiedDependencyException(
mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
"Could not convert argument value of type [" +
- ObjectUtils.nullSafeClassName(valueHolder.getValue()) +
- "] to required type [" + paramType.getName() + "]: " + ex.getMessage());
+ ObjectUtils.nullSafeClassName(valueHolder.getValue()) +
+ "] to required type [" + paramType.getName() + "]: " + ex.getMessage());
+ }
+ Object sourceHolder = valueHolder.getSource();
+ if (sourceHolder instanceof ConstructorArgumentValues.ValueHolder) {
+ Object sourceValue = ((ConstructorArgumentValues.ValueHolder) sourceHolder).getValue();
+ args.resolveNecessary = true;
+ args.preparedArguments[paramIndex] = sourceValue;
}
}
args.arguments[paramIndex] = convertedValue;
@@ -822,6 +798,7 @@ class ConstructorResolver {
/**
* Template method for resolving the specified argument which is supposed to be autowired.
*/
+ @Nullable
protected Object resolveAutowiredArgument(
MethodParameter param, String beanName, @Nullable Set autowiredBeanNames, TypeConverter typeConverter) {
@@ -837,8 +814,7 @@ class ConstructorResolver {
}
-
- static InjectionPoint setCurrentInjectionPoint(InjectionPoint injectionPoint) {
+ static InjectionPoint setCurrentInjectionPoint(@Nullable InjectionPoint injectionPoint) {
InjectionPoint old = currentInjectionPoint.get();
if (injectionPoint != null) {
currentInjectionPoint.set(injectionPoint);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
index 686fa1bec4..638bee35e7 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
@@ -41,7 +41,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-
import javax.inject.Provider;
import org.springframework.beans.BeanUtils;
@@ -186,7 +185,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* Create a new DefaultListableBeanFactory with the given parent.
* @param parentBeanFactory the parent BeanFactory
*/
- public DefaultListableBeanFactory(BeanFactory parentBeanFactory) {
+ public DefaultListableBeanFactory(@Nullable BeanFactory parentBeanFactory) {
super(parentBeanFactory);
}
@@ -285,12 +284,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
Assert.notNull(autowireCandidateResolver, "AutowireCandidateResolver must not be null");
if (autowireCandidateResolver instanceof BeanFactoryAware) {
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- ((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(DefaultListableBeanFactory.this);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(DefaultListableBeanFactory.this);
+ return null;
}, getAccessControlContext());
}
else {
@@ -334,14 +330,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
- public T getBean(Class requiredType, Object... args) throws BeansException {
+ public T getBean(Class requiredType, @Nullable Object... args) throws BeansException {
NamedBeanHolder namedBean = resolveNamedBean(requiredType, args);
if (namedBean != null) {
return namedBean.getBeanInstance();
}
BeanFactory parent = getParentBeanFactory();
if (parent != null) {
- return parent.getBean(requiredType, args);
+ return (args != null ? parent.getBean(requiredType, args) : parent.getBean(requiredType));
}
throw new NoSuchBeanDefinitionException(requiredType);
}
@@ -373,7 +369,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
- public String[] getBeanNamesForType(@Nullable ResolvableType type) {
+ public String[] getBeanNamesForType(ResolvableType type) {
return doGetBeanNamesForType(type, true, true);
}
@@ -492,7 +488,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* defines a factory method for
* @return whether eager initialization is necessary
*/
- private boolean requiresEagerInitForType(String factoryBeanName) {
+ private boolean requiresEagerInitForType(@Nullable String factoryBeanName) {
return (factoryBeanName != null && isFactoryBean(factoryBeanName) && !containsSingleton(factoryBeanName));
}
@@ -592,7 +588,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
//---------------------------------------------------------------------
@Override
- public void registerResolvableDependency(Class> dependencyType, Object autowiredValue) {
+ public void registerResolvableDependency(Class> dependencyType, @Nullable Object autowiredValue) {
Assert.notNull(dependencyType, "Dependency type must not be null");
if (autowiredValue != null) {
if (!(autowiredValue instanceof ObjectFactory || dependencyType.isInstance(autowiredValue))) {
@@ -671,7 +667,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
- public BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException {
+ public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException {
BeanDefinition bd = this.beanDefinitionMap.get(beanName);
if (bd == null) {
if (this.logger.isTraceEnabled()) {
@@ -735,12 +731,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
final FactoryBean> factory = (FactoryBean>) getBean(FACTORY_BEAN_PREFIX + beanName);
boolean isEagerInit;
if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
- isEagerInit = AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Boolean run() {
- return ((SmartFactoryBean>) factory).isEagerInit();
- }
- }, getAccessControlContext());
+ isEagerInit = AccessController.doPrivileged((PrivilegedAction) () ->
+ ((SmartFactoryBean>) factory).isEagerInit(),
+ getAccessControlContext());
}
else {
isEagerInit = (factory instanceof SmartFactoryBean &&
@@ -762,12 +755,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
if (singletonInstance instanceof SmartInitializingSingleton) {
final SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton) singletonInstance;
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- smartSingleton.afterSingletonsInstantiated();
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ smartSingleton.afterSingletonsInstantiated();
+ return null;
}, getAccessControlContext());
}
else {
@@ -991,7 +981,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@SuppressWarnings("unchecked")
@Nullable
- private NamedBeanHolder resolveNamedBean(Class requiredType, Object... args) throws BeansException {
+ private NamedBeanHolder resolveNamedBean(Class requiredType, @Nullable Object... args) throws BeansException {
Assert.notNull(requiredType, "Required type must not be null");
String[] candidateNames = getBeanNamesForType(requiredType);
@@ -1039,7 +1029,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
- public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
+ public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
@Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
@@ -1064,7 +1054,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Nullable
- public Object doResolveDependency(DependencyDescriptor descriptor, String beanName,
+ public Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName,
@Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor);
@@ -1137,8 +1127,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
- private Object resolveMultipleBeans(DependencyDescriptor descriptor, String beanName,
- Set autowiredBeanNames, TypeConverter typeConverter) {
+ private Object resolveMultipleBeans(DependencyDescriptor descriptor, @Nullable String beanName,
+ @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) {
Class> type = descriptor.getDependencyType();
if (type.isArray()) {
@@ -1221,6 +1211,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
(Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type))));
}
+ @Nullable
private Comparator adaptDependencyComparator(Map matchingBeans) {
Comparator comparator = getDependencyComparator();
if (comparator instanceof OrderComparator) {
@@ -1254,7 +1245,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* @see #autowireConstructor
*/
protected Map findAutowireCandidates(
- String beanName, Class> requiredType, DependencyDescriptor descriptor) {
+ @Nullable String beanName, Class> requiredType, DependencyDescriptor descriptor) {
String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
this, requiredType, true, descriptor.isEager());
@@ -1459,7 +1450,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* Determine whether the given candidate name matches the bean name or the aliases
* stored in this bean definition.
*/
- protected boolean matchesBeanName(String beanName, String candidateName) {
+ protected boolean matchesBeanName(String beanName, @Nullable String candidateName) {
return (candidateName != null &&
(candidateName.equals(beanName) || ObjectUtils.containsElement(getAliases(beanName), candidateName)));
}
@@ -1469,7 +1460,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* i.e. whether the candidate points back to the original bean or to a factory method
* on the original bean.
*/
- private boolean isSelfReference(String beanName, String candidateName) {
+ private boolean isSelfReference(@Nullable String beanName, @Nullable String candidateName) {
return (beanName != null && candidateName != null &&
(beanName.equals(candidateName) || (containsBeanDefinition(candidateName) &&
beanName.equals(getMergedLocalBeanDefinition(candidateName).getFactoryBeanName()))));
@@ -1502,7 +1493,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
// Probably a proxy interfering with target type match -> throw meaningful exception.
Object beanInstance = getSingleton(beanName, false);
Class> beanType = (beanInstance != null ? beanInstance.getClass() : predictBeanType(beanName, mbd));
- if (!type.isAssignableFrom((beanType))) {
+ if (beanType != null && !type.isAssignableFrom(beanType)) {
throw new BeanNotOfRequiredTypeException(beanName, type, beanType);
}
}
@@ -1517,7 +1508,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
/**
* Create an {@link Optional} wrapper for the specified dependency.
*/
- private Optional> createOptionalDependency(DependencyDescriptor descriptor, String beanName, final Object... args) {
+ private Optional> createOptionalDependency(
+ DependencyDescriptor descriptor, @Nullable String beanName, final Object... args) {
+
DependencyDescriptor descriptorToUse = new NestedDependencyDescriptor(descriptor) {
@Override
public boolean isRequired() {
@@ -1606,7 +1599,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
private final String beanName;
- public DependencyObjectProvider(DependencyDescriptor descriptor, String beanName) {
+ public DependencyObjectProvider(DependencyDescriptor descriptor, @Nullable String beanName) {
this.descriptor = new NestedDependencyDescriptor(descriptor);
this.optional = (this.descriptor.getDependencyType() == Optional.class);
this.beanName = beanName;
@@ -1681,11 +1674,12 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
*/
private class Jsr330DependencyProvider extends DependencyObjectProvider implements Provider {
- public Jsr330DependencyProvider(DependencyDescriptor descriptor, String beanName) {
+ public Jsr330DependencyProvider(DependencyDescriptor descriptor, @Nullable String beanName) {
super(descriptor, beanName);
}
@Override
+ @Nullable
public Object get() throws BeansException {
return getObject();
}
@@ -1697,7 +1691,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
*/
private class Jsr330ProviderFactory {
- public Object createDependencyProvider(DependencyDescriptor descriptor, String beanName) {
+ public Object createDependencyProvider(DependencyDescriptor descriptor, @Nullable String beanName) {
return new Jsr330DependencyProvider(descriptor, beanName);
}
}
@@ -1737,7 +1731,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Nullable
- private RootBeanDefinition getRootBeanDefinition(String beanName) {
+ private RootBeanDefinition getRootBeanDefinition(@Nullable String beanName) {
if (beanName != null && containsBeanDefinition(beanName)) {
BeanDefinition bd = getMergedBeanDefinition(beanName);
if (bd instanceof RootBeanDefinition) {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
index f1ea506da0..62da7042a3 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
@@ -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.
@@ -141,7 +141,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
* @param beanName the name of the bean
* @param singletonObject the singleton object
*/
- protected void addSingleton(String beanName, Object singletonObject) {
+ protected void addSingleton(String beanName, @Nullable Object singletonObject) {
synchronized (this.singletonObjects) {
this.singletonObjects.put(beanName, (singletonObject != null ? singletonObject : NULL_OBJECT));
this.singletonFactories.remove(beanName);
@@ -209,6 +209,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
* with, if necessary
* @return the registered singleton object
*/
+ @Nullable
public Object getSingleton(String beanName, ObjectFactory> singletonFactory) {
Assert.notNull(beanName, "'beanName' must not be null");
synchronized (this.singletonObjects) {
@@ -562,7 +563,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
* @param beanName the name of the bean
* @param bean the bean instance to destroy
*/
- protected void destroyBean(String beanName, DisposableBean bean) {
+ protected void destroyBean(String beanName, @Nullable DisposableBean bean) {
// Trigger destruction of dependent beans first...
Set dependencies = this.dependentBeanMap.remove(beanName);
if (dependencies != null) {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
index 5aa6a59164..da2572ee8f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
@@ -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.
@@ -95,7 +95,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* (potentially DestructionAwareBeanPostProcessor), if any
*/
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
- List postProcessors, AccessControlContext acc) {
+ List postProcessors, @Nullable AccessControlContext acc) {
Assert.notNull(bean, "Disposable bean must not be null");
this.bean = bean;
@@ -151,7 +151,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
*/
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
boolean nonPublicAccessAllowed, String destroyMethodName,
- List postProcessors) {
+ @Nullable List postProcessors) {
this.bean = bean;
this.beanName = beanName;
@@ -206,6 +206,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
* @param processors the List to search
* @return the filtered List of DestructionAwareBeanPostProcessors
*/
+ @Nullable
private List filterPostProcessors(List processors, Object bean) {
List filteredPostProcessors = null;
if (!CollectionUtils.isEmpty(processors)) {
@@ -242,12 +243,9 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
try {
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- ((DisposableBean) bean).destroy();
- return null;
- }
+ AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
+ ((DisposableBean) bean).destroy();
+ return null;
}, acc);
}
else {
@@ -277,15 +275,11 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
+ @Nullable
private Method determineDestroyMethod() {
try {
if (System.getSecurityManager() != null) {
- return AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Method run() {
- return findDestroyMethod();
- }
- });
+ return AccessController.doPrivileged((PrivilegedAction) () -> findDestroyMethod());
}
else {
return findDestroyMethod();
@@ -297,6 +291,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
}
+ @Nullable
private Method findDestroyMethod() {
return (this.nonPublicAccessAllowed ?
BeanUtils.findMethodWithMinimalParameters(this.bean.getClass(), this.destroyMethodName) :
@@ -321,21 +316,13 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
try {
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- ReflectionUtils.makeAccessible(destroyMethod);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(destroyMethod);
+ return null;
});
try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- destroyMethod.invoke(bean, args);
- return null;
- }
- }, acc);
+ AccessController.doPrivileged((PrivilegedExceptionAction) () ->
+ destroyMethod.invoke(bean, args), acc);
}
catch (PrivilegedActionException pax) {
throw (InvocationTargetException) pax.getException();
@@ -409,14 +396,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
for (BeanPostProcessor processor : postProcessors) {
if (processor instanceof DestructionAwareBeanPostProcessor) {
DestructionAwareBeanPostProcessor dabpp = (DestructionAwareBeanPostProcessor) processor;
- try {
- if (dabpp.requiresDestruction(bean)) {
- return true;
- }
- }
- catch (AbstractMethodError err) {
- // A pre-4.3 third-party DestructionAwareBeanPostProcessor...
- // As of 5.0, we can let requiresDestruction be a Java 8 default method which returns true.
+ if (dabpp.requiresDestruction(bean)) {
return true;
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java
index 42a1582936..3184468492 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/FactoryBeanRegistrySupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,12 +57,8 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
protected Class> getTypeForFactoryBean(final FactoryBean> factoryBean) {
try {
if (System.getSecurityManager() != null) {
- return AccessController.doPrivileged(new PrivilegedAction>() {
- @Override
- public Class> run() {
- return factoryBean.getObjectType();
- }
- }, getAccessControlContext());
+ return AccessController.doPrivileged((PrivilegedAction>) () ->
+ factoryBean.getObjectType(), getAccessControlContext());
}
else {
return factoryBean.getObjectType();
@@ -98,6 +94,7 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
* @throws BeanCreationException if FactoryBean object creation failed
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
+ @Nullable
protected Object getObjectFromFactoryBean(FactoryBean> factory, String beanName, boolean shouldPostProcess) {
if (factory.isSingleton() && containsSingleton(beanName)) {
synchronized (getSingletonMutex()) {
@@ -148,6 +145,7 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
* @throws BeanCreationException if FactoryBean object creation failed
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
+ @Nullable
private Object doGetObjectFromFactoryBean(final FactoryBean> factory, final String beanName)
throws BeanCreationException {
@@ -156,12 +154,8 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
if (System.getSecurityManager() != null) {
AccessControlContext acc = getAccessControlContext();
try {
- object = AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Object run() throws Exception {
- return factory.getObject();
- }
- }, acc);
+ object = AccessController.doPrivileged((PrivilegedExceptionAction) () ->
+ factory.getObject(), acc);
}
catch (PrivilegedActionException pae) {
throw pae.getException();
@@ -197,6 +191,7 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
* @return the object to expose
* @throws org.springframework.beans.BeansException if any post-processing failed
*/
+ @Nullable
protected Object postProcessObjectFromFactoryBean(Object object, String beanName) throws BeansException {
return object;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java
index 2052734096..2dbcedf48f 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java
@@ -52,6 +52,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
this.beanFactory = beanFactory;
}
+ @Nullable
protected final BeanFactory getBeanFactory() {
return this.beanFactory;
}
@@ -63,7 +64,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
// If explicitly false, do not proceed with any other checks...
return false;
}
- return (descriptor == null || checkGenericTypeMatch(bdHolder, descriptor));
+ return checkGenericTypeMatch(bdHolder, descriptor);
}
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java
index f4a84638ae..e2f38783ff 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstantiationStrategy.java
@@ -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.
@@ -62,7 +62,7 @@ public interface InstantiationStrategy {
* @throws BeansException if the instantiation attempt failed
*/
Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
- Constructor> ctor, Object... args) throws BeansException;
+ Constructor> ctor, @Nullable Object... args) throws BeansException;
/**
* Return an instance of the bean with the given name in this factory,
@@ -80,6 +80,7 @@ public interface InstantiationStrategy {
* @throws BeansException if the instantiation attempt failed
*/
Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
- @Nullable Object factoryBean, Method factoryMethod, Object... args) throws BeansException;
+ @Nullable Object factoryBean, Method factoryMethod, @Nullable Object... args)
+ throws BeansException;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java
index 321a72101d..a35c413d29 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java
@@ -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.
@@ -54,7 +54,7 @@ public class ManagedList extends ArrayList implements Mergeable, BeanMetad
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java
index 573796d0a8..ad8682abbe 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java
@@ -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.
@@ -55,7 +55,7 @@ public class ManagedMap extends LinkedHashMap implements Mergeable,
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java
index e6f7cf7952..ee64afb9e7 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java
@@ -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.
@@ -42,7 +42,7 @@ public class ManagedProperties extends Properties implements Mergeable, BeanMeta
* Set the configuration source {@code Object} for this metadata element.
*
The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java
index ff0b888b68..24d83e071d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class ManagedSet extends LinkedHashSet implements Mergeable, BeanMe
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java
index bf11af7eb5..f3a4b36168 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java
@@ -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.
@@ -19,6 +19,7 @@ package org.springframework.beans.factory.support;
import java.lang.reflect.Method;
import org.springframework.beans.BeanMetadataElement;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -82,7 +83,7 @@ public abstract class MethodOverride implements BeanMetadataElement {
* Set the configuration source {@code Object} for this metadata element.
*
The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java
index 2d52488ad4..976e3780cd 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java
@@ -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.
@@ -60,7 +60,7 @@ public class MethodOverrides {
/**
* Copy all given method overrides into this object.
*/
- public void addOverrides(MethodOverrides other) {
+ public void addOverrides(@Nullable MethodOverrides other) {
if (other != null) {
this.modified = true;
this.overrides.addAll(other.overrides);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java
index d48f80dae4..12a0077e0e 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/PropertiesBeanDefinitionReader.java
@@ -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.
@@ -184,7 +184,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
* The default is DefaultPropertiesPersister.
* @see org.springframework.util.DefaultPropertiesPersister
*/
- public void setPropertiesPersister(PropertiesPersister propertiesPersister) {
+ public void setPropertiesPersister(@Nullable PropertiesPersister propertiesPersister) {
this.propertiesPersister =
(propertiesPersister != null ? propertiesPersister : new DefaultPropertiesPersister());
}
@@ -435,8 +435,8 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
else if (SINGLETON_KEY.equals(property)) {
// Spring 1.2 style
String val = StringUtils.trimWhitespace((String) entry.getValue());
- scope = ((val == null || TRUE_VALUE.equals(val) ? GenericBeanDefinition.SCOPE_SINGLETON :
- GenericBeanDefinition.SCOPE_PROTOTYPE));
+ scope = ("".equals(val) || TRUE_VALUE.equals(val) ? GenericBeanDefinition.SCOPE_SINGLETON :
+ GenericBeanDefinition.SCOPE_PROTOTYPE);
}
else if (LAZY_INIT_KEY.equals(property)) {
String val = StringUtils.trimWhitespace((String) entry.getValue());
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
index 777413e60f..5a6ba8ec43 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
@@ -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.
@@ -290,7 +290,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* Specify the target type of this bean definition, if known in advance.
* @since 3.2.2
*/
- public void setTargetType(Class> targetType) {
+ public void setTargetType(@Nullable Class> targetType) {
this.targetType = (targetType != null ? ResolvableType.forClass(targetType) : null);
}
@@ -299,6 +299,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* (either specified in advance or resolved on first instantiation).
* @since 3.2.2
*/
+ @Nullable
public Class> getTargetType() {
if (this.resolvedTargetType != null) {
return this.resolvedTargetType;
@@ -319,7 +320,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* Check whether the given candidate qualifies as a factory method.
*/
public boolean isFactoryMethod(Method candidate) {
- return (candidate != null && candidate.getName().equals(getFactoryMethodName()));
+ return candidate.getName().equals(getFactoryMethodName());
}
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java
index b22bd1470d..ddbf3b4127 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java
@@ -18,6 +18,7 @@ package org.springframework.beans.factory.support;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.DependencyDescriptor;
+import org.springframework.lang.Nullable;
/**
* {@link AutowireCandidateResolver} implementation to use when no annotation
@@ -45,7 +46,7 @@ public class SimpleAutowireCandidateResolver implements AutowireCandidateResolve
}
@Override
- public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, String beanName) {
+ public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) {
return null;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleBeanDefinitionRegistry.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleBeanDefinitionRegistry.java
index 623c318114..a45e488ebe 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleBeanDefinitionRegistry.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleBeanDefinitionRegistry.java
@@ -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.
@@ -23,7 +23,6 @@ import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.SimpleAliasRegistry;
-import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -58,7 +57,7 @@ public class SimpleBeanDefinitionRegistry extends SimpleAliasRegistry implements
}
@Override
- public BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException {
+ public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException {
BeanDefinition bd = this.beanDefinitionMap.get(beanName);
if (bd == null) {
throw new NoSuchBeanDefinitionException(beanName);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java
index 4ffe761ff6..1fd0e8126d 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java
@@ -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.
@@ -71,15 +71,12 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
}
try {
if (System.getSecurityManager() != null) {
- constructorToUse = AccessController.doPrivileged(new PrivilegedExceptionAction>() {
- @Override
- public Constructor> run() throws Exception {
- return clazz.getDeclaredConstructor((Class[]) null);
- }
- });
+ constructorToUse = AccessController.doPrivileged(
+ (PrivilegedExceptionAction>) () ->
+ clazz.getDeclaredConstructor());
}
else {
- constructorToUse = clazz.getDeclaredConstructor((Class[]) null);
+ constructorToUse = clazz.getDeclaredConstructor();
}
bd.resolvedConstructorOrFactoryMethod = constructorToUse;
}
@@ -102,26 +99,23 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
* the Method Injection specified in the given RootBeanDefinition.
* Instantiation should use a no-arg constructor.
*/
- protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner) {
+ protected Object instantiateWithMethodInjection(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner) {
throw new UnsupportedOperationException("Method Injection not supported in SimpleInstantiationStrategy");
}
@Override
public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
- final Constructor> ctor, Object... args) {
+ final Constructor> ctor, @Nullable Object... args) {
if (bd.getMethodOverrides().isEmpty()) {
if (System.getSecurityManager() != null) {
// use own privileged to change accessibility (when security is on)
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- ReflectionUtils.makeAccessible(ctor);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(ctor);
+ return null;
});
}
- return BeanUtils.instantiateClass(ctor, args);
+ return (args != null ? BeanUtils.instantiateClass(ctor, args) : BeanUtils.instantiateClass(ctor));
}
else {
return instantiateWithMethodInjection(bd, beanName, owner, ctor, args);
@@ -134,24 +128,21 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy {
* the Method Injection specified in the given RootBeanDefinition.
* Instantiation should use the given constructor and parameters.
*/
- protected Object instantiateWithMethodInjection(RootBeanDefinition bd, String beanName, BeanFactory owner,
- @Nullable Constructor> ctor, Object... args) {
+ protected Object instantiateWithMethodInjection(RootBeanDefinition bd, @Nullable String beanName,
+ BeanFactory owner, @Nullable Constructor> ctor, @Nullable Object... args) {
throw new UnsupportedOperationException("Method Injection not supported in SimpleInstantiationStrategy");
}
@Override
public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner,
- @Nullable Object factoryBean, final Method factoryMethod, Object... args) {
+ @Nullable Object factoryBean, final Method factoryMethod, @Nullable Object... args) {
try {
if (System.getSecurityManager() != null) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- ReflectionUtils.makeAccessible(factoryMethod);
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction) () -> {
+ ReflectionUtils.makeAccessible(factoryMethod);
+ return null;
});
}
else {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
index b39f08c2c6..d72031c8b0 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java
@@ -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,6 +36,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
+import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
@@ -120,7 +121,11 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
if (bean instanceof FactoryBean && !BeanFactoryUtils.isFactoryDereference(name)) {
try {
- return ((FactoryBean>) bean).getObject();
+ Object exposedObject = ((FactoryBean>) bean).getObject();
+ if (exposedObject == null) {
+ throw new BeanCreationException(beanName, "FactoryBean exposed null object");
+ }
+ return exposedObject;
}
catch (Exception ex) {
throw new BeanCreationException(beanName, "FactoryBean threw exception on object creation", ex);
@@ -135,12 +140,21 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
@SuppressWarnings("unchecked")
public T getBean(String name, @Nullable Class requiredType) throws BeansException {
Object bean = getBean(name);
- if (requiredType != null && !requiredType.isAssignableFrom(bean.getClass())) {
+ if (requiredType != null && !requiredType.isInstance(bean)) {
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
return (T) bean;
}
+ @Override
+ public Object getBean(String name, Object... args) throws BeansException {
+ if (!ObjectUtils.isEmpty(args)) {
+ throw new UnsupportedOperationException(
+ "StaticListableBeanFactory does not support explicit bean creation arguments");
+ }
+ return getBean(name);
+ }
+
@Override
public T getBean(Class requiredType) throws BeansException {
String[] beanNames = getBeanNamesForType(requiredType);
@@ -155,18 +169,9 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
}
}
- @Override
- public Object getBean(String name, Object... args) throws BeansException {
- if (args != null) {
- throw new UnsupportedOperationException(
- "StaticListableBeanFactory does not support explicit bean creation arguments");
- }
- return getBean(name);
- }
-
@Override
public T getBean(Class requiredType, Object... args) throws BeansException {
- if (args != null) {
+ if (!ObjectUtils.isEmpty(args)) {
throw new UnsupportedOperationException(
"StaticListableBeanFactory does not support explicit bean creation arguments");
}
@@ -200,7 +205,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
}
@Override
- public boolean isTypeMatch(String name, Class> typeToMatch) throws NoSuchBeanDefinitionException {
+ public boolean isTypeMatch(String name, @Nullable Class> typeToMatch) throws NoSuchBeanDefinitionException {
Class> type = getType(name);
return (typeToMatch == null || (type != null && typeToMatch.isAssignableFrom(type)));
}
@@ -353,7 +358,8 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
public A findAnnotationOnBean(String beanName, Class annotationType)
throws NoSuchBeanDefinitionException{
- return AnnotationUtils.findAnnotation(getType(beanName), annotationType);
+ Class> beanType = getType(beanName);
+ return (beanType != null ? AnnotationUtils.findAnnotation(beanType, annotationType) : null);
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java
index a1e4a9f422..961fb47987 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java
@@ -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.
@@ -120,7 +120,7 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
* Typically called by an aspect, for all bean instances matched by a pointcut.
* @param beanInstance the bean instance to configure (must not be {@code null})
*/
- public void configureBean(@Nullable Object beanInstance) {
+ public void configureBean(Object beanInstance) {
if (this.beanFactory == null) {
if (logger.isDebugEnabled()) {
logger.debug("BeanFactory has not been set on " + ClassUtils.getShortName(getClass()) + ": " +
@@ -137,8 +137,8 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
}
try {
- if (bwi.indicatesAutowiring() ||
- (bwi.isDefaultBeanName() && !this.beanFactory.containsBean(bwi.getBeanName()))) {
+ if (bwi.indicatesAutowiring() || (bwi.isDefaultBeanName() && bwi.getBeanName() != null &&
+ !this.beanFactory.containsBean(bwi.getBeanName()))) {
// Perform autowiring (also applying standard factory / post-processor callbacks).
this.beanFactory.autowireBeanProperties(beanInstance, bwi.getAutowireMode(), bwi.getDependencyCheck());
Object result = this.beanFactory.initializeBean(beanInstance, bwi.getBeanName());
@@ -168,11 +168,12 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
}
}
- private void checkExposedObject(Object exposedObject, Object originalBeanInstance) {
+ private void checkExposedObject(@Nullable Object exposedObject, Object originalBeanInstance) {
if (exposedObject != originalBeanInstance) {
throw new IllegalStateException("Post-processor tried to replace bean instance of type [" +
originalBeanInstance.getClass().getName() + "] with (proxy) object of type [" +
- exposedObject.getClass().getName() + "] - not supported for aspect-configured classes!");
+ (exposedObject != null ? exposedObject.getClass().getName() : null) +
+ "] - not supported for aspect-configured classes!");
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java
index f40a4b34df..aeba4e7741 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java
@@ -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.
@@ -84,7 +84,8 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
}
}
catch (BeanDefinitionStoreException ex) {
- parserContext.getReaderContext().error(ex.getMessage(), element);
+ String msg = ex.getMessage();
+ parserContext.getReaderContext().error((msg != null ? msg : ex.toString()), element);
return null;
}
}
@@ -141,14 +142,15 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
/**
* Central template method to actually parse the supplied {@link Element}
* into one or more {@link BeanDefinition BeanDefinitions}.
- * @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
+ * @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
* @param parserContext the object encapsulating the current state of the parsing process;
* provides access to a {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
* @return the primary {@link BeanDefinition} resulting from the parsing of the supplied {@link Element}
* @see #parse(org.w3c.dom.Element, ParserContext)
* @see #postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)
*/
- protected abstract AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext);
+ @Nullable
+ protected abstract AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext);
/**
* Should an ID be generated instead of read from the passed in {@link Element}?
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java
index 92324acd4e..757482cd3a 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser.java
@@ -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.
@@ -58,7 +58,7 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef
* @see #doParse
*/
@Override
- protected final AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext) {
+ protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
String parentName = getParentName(element);
if (parentName != null) {
@@ -77,7 +77,10 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
if (parserContext.isNested()) {
// Inner bean definition must receive same scope as containing bean.
- builder.setScope(parserContext.getContainingBeanDefinition().getScope());
+ String scopeName = parserContext.getContainingBeanDefinition().getScope();
+ if (scopeName != null) {
+ builder.setScope(scopeName);
+ }
}
if (parserContext.isDefaultLazyInit()) {
// Default-lazy-init applies to custom bean definitions as well.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
index 9685d15ba3..2dd1665b1c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java
@@ -265,9 +265,10 @@ public class BeanDefinitionParserDelegate {
}
/**
- * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull the
- * source metadata from the supplied {@link Element}.
+ * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor}
+ * to pull the source metadata from the supplied {@link Element}.
*/
+ @Nullable
protected Object extractSource(Element ele) {
return this.readerContext.extractSource(ele);
}
@@ -370,10 +371,8 @@ public class BeanDefinitionParserDelegate {
}
/**
- * Return the defaults definition object, or {@code null} if the
- * defaults have been initialized yet.
+ * Return the defaults definition object.
*/
- @Nullable
public DocumentDefaultsDefinition getDefaults() {
return this.defaults;
}
@@ -395,6 +394,7 @@ public class BeanDefinitionParserDelegate {
* Return any patterns provided in the 'default-autowire-candidates'
* attribute of the top-level {@code } element.
*/
+ @Nullable
public String[] getAutowireCandidatePatterns() {
String candidatePattern = this.defaults.getAutowireCandidates();
return (candidatePattern != null ? StringUtils.commaDelimitedListToStringArray(candidatePattern) : null);
@@ -504,7 +504,7 @@ public class BeanDefinitionParserDelegate {
*/
@Nullable
public AbstractBeanDefinition parseBeanDefinitionElement(
- Element ele, String beanName, BeanDefinition containingBean) {
+ Element ele, String beanName, @Nullable BeanDefinition containingBean) {
this.parseState.push(new BeanEntry(beanName));
@@ -512,12 +512,12 @@ public class BeanDefinitionParserDelegate {
if (ele.hasAttribute(CLASS_ATTRIBUTE)) {
className = ele.getAttribute(CLASS_ATTRIBUTE).trim();
}
+ String parent = null;
+ if (ele.hasAttribute(PARENT_ATTRIBUTE)) {
+ parent = ele.getAttribute(PARENT_ATTRIBUTE);
+ }
try {
- String parent = null;
- if (ele.hasAttribute(PARENT_ATTRIBUTE)) {
- parent = ele.getAttribute(PARENT_ATTRIBUTE);
- }
AbstractBeanDefinition bd = createBeanDefinition(className, parent);
parseBeanDefinitionAttributes(ele, beanName, containingBean, bd);
@@ -560,7 +560,7 @@ public class BeanDefinitionParserDelegate {
* @return a bean definition initialized according to the bean element attributes
*/
public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName,
- BeanDefinition containingBean, AbstractBeanDefinition bd) {
+ @Nullable BeanDefinition containingBean, AbstractBeanDefinition bd) {
if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele);
@@ -644,7 +644,7 @@ public class BeanDefinitionParserDelegate {
* @return the newly created bean definition
* @throws ClassNotFoundException if bean class resolution was attempted but failed
*/
- protected AbstractBeanDefinition createBeanDefinition(String className, String parentName)
+ protected AbstractBeanDefinition createBeanDefinition(@Nullable String className, @Nullable String parentName)
throws ClassNotFoundException {
return BeanDefinitionReaderUtils.createBeanDefinition(
@@ -961,6 +961,7 @@ public class BeanDefinitionParserDelegate {
}
}
+ @Nullable
public Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd) {
return parsePropertySubElement(ele, bd, null);
}
@@ -973,7 +974,7 @@ public class BeanDefinitionParserDelegate {
* {@code } tag that might be created
*/
@Nullable
- public Object parsePropertySubElement(Element ele, BeanDefinition bd, @Nullable String defaultValueType) {
+ public Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd, @Nullable String defaultValueType) {
if (!isDefaultNamespace(ele)) {
return parseNestedCustomElement(ele, bd);
}
@@ -1062,7 +1063,7 @@ public class BeanDefinitionParserDelegate {
/**
* Return a typed String value Object for the given value element.
*/
- public Object parseValueElement(Element ele, String defaultTypeName) {
+ public Object parseValueElement(Element ele, @Nullable String defaultTypeName) {
// It's a literal value.
String value = DomUtils.getTextValue(ele);
String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE);
@@ -1086,7 +1087,7 @@ public class BeanDefinitionParserDelegate {
* Build a typed String value Object for the given raw value.
* @see org.springframework.beans.factory.config.TypedStringValue
*/
- protected TypedStringValue buildTypedStringValue(String value, String targetTypeName)
+ protected TypedStringValue buildTypedStringValue(String value, @Nullable String targetTypeName)
throws ClassNotFoundException {
ClassLoader classLoader = this.readerContext.getBeanClassLoader();
@@ -1107,7 +1108,7 @@ public class BeanDefinitionParserDelegate {
/**
* Parse an array element.
*/
- public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
+ public Object parseArrayElement(Element arrayEle, @Nullable BeanDefinition bd) {
String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
NodeList nl = arrayEle.getChildNodes();
ManagedArray target = new ManagedArray(elementType, nl.getLength());
@@ -1121,7 +1122,7 @@ public class BeanDefinitionParserDelegate {
/**
* Parse a list element.
*/
- public List parseListElement(Element collectionEle, BeanDefinition bd) {
+ public List parseListElement(Element collectionEle, @Nullable BeanDefinition bd) {
String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
NodeList nl = collectionEle.getChildNodes();
ManagedList target = new ManagedList<>(nl.getLength());
@@ -1135,7 +1136,7 @@ public class BeanDefinitionParserDelegate {
/**
* Parse a set element.
*/
- public Set parseSetElement(Element collectionEle, BeanDefinition bd) {
+ public Set parseSetElement(Element collectionEle, @Nullable BeanDefinition bd) {
String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
NodeList nl = collectionEle.getChildNodes();
ManagedSet target = new ManagedSet<>(nl.getLength());
@@ -1147,7 +1148,7 @@ public class BeanDefinitionParserDelegate {
}
protected void parseCollectionElements(
- NodeList elementNodes, Collection target, BeanDefinition bd, String defaultElementType) {
+ NodeList elementNodes, Collection target, @Nullable BeanDefinition bd, String defaultElementType) {
for (int i = 0; i < elementNodes.getLength(); i++) {
Node node = elementNodes.item(i);
@@ -1160,7 +1161,7 @@ public class BeanDefinitionParserDelegate {
/**
* Parse a map element.
*/
- public Map parseMapElement(Element mapEle, BeanDefinition bd) {
+ public Map parseMapElement(Element mapEle, @Nullable BeanDefinition bd) {
String defaultKeyType = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
String defaultValueType = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
@@ -1297,7 +1298,8 @@ public class BeanDefinitionParserDelegate {
/**
* Parse a key sub-element of a map element.
*/
- protected Object parseKeyElement(Element keyEle, BeanDefinition bd, String defaultKeyTypeName) {
+ @Nullable
+ protected Object parseKeyElement(Element keyEle, @Nullable BeanDefinition bd, String defaultKeyTypeName) {
NodeList nl = keyEle.getChildNodes();
Element subElement = null;
for (int i = 0; i < nl.getLength(); i++) {
@@ -1312,6 +1314,9 @@ public class BeanDefinitionParserDelegate {
}
}
}
+ if (subElement == null) {
+ return null;
+ }
return parsePropertySubElement(subElement, bd, defaultKeyTypeName);
}
@@ -1350,6 +1355,7 @@ public class BeanDefinitionParserDelegate {
return TRUE_VALUE.equals(value);
}
+ @Nullable
public BeanDefinition parseCustomElement(Element ele) {
return parseCustomElement(ele, null);
}
@@ -1357,6 +1363,9 @@ public class BeanDefinitionParserDelegate {
@Nullable
public BeanDefinition parseCustomElement(Element ele, @Nullable BeanDefinition containingBd) {
String namespaceUri = getNamespaceURI(ele);
+ if (namespaceUri == null) {
+ return null;
+ }
NamespaceHandler handler = this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler == null) {
error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", ele);
@@ -1393,15 +1402,19 @@ public class BeanDefinitionParserDelegate {
}
public BeanDefinitionHolder decorateIfRequired(
- Node node, BeanDefinitionHolder originalDef, BeanDefinition containingBd) {
+ Node node, BeanDefinitionHolder originalDef, @Nullable BeanDefinition containingBd) {
String namespaceUri = getNamespaceURI(node);
- if (!isDefaultNamespace(namespaceUri)) {
+ if (namespaceUri != null && !isDefaultNamespace(namespaceUri)) {
NamespaceHandler handler = this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler != null) {
- return handler.decorate(node, originalDef, new ParserContext(this.readerContext, this, containingBd));
+ BeanDefinitionHolder decorated =
+ handler.decorate(node, originalDef, new ParserContext(this.readerContext, this, containingBd));
+ if (decorated != null) {
+ return decorated;
+ }
}
- else if (namespaceUri != null && namespaceUri.startsWith("http://www.springframework.org/")) {
+ else if (namespaceUri.startsWith("http://www.springframework.org/")) {
error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", node);
}
else {
@@ -1415,7 +1428,7 @@ public class BeanDefinitionParserDelegate {
}
@Nullable
- private BeanDefinitionHolder parseNestedCustomElement(Element ele, BeanDefinition containingBd) {
+ private BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable BeanDefinition containingBd) {
BeanDefinition innerDefinition = parseCustomElement(ele, containingBd);
if (innerDefinition == null) {
error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " +
@@ -1439,6 +1452,7 @@ public class BeanDefinitionParserDelegate {
* different namespace identification mechanism.
* @param node the node
*/
+ @Nullable
public String getNamespaceURI(Node node) {
return node.getNamespaceURI();
}
@@ -1467,7 +1481,7 @@ public class BeanDefinitionParserDelegate {
return desiredName.equals(node.getNodeName()) || desiredName.equals(getLocalName(node));
}
- public boolean isDefaultNamespace(String namespaceUri) {
+ public boolean isDefaultNamespace(@Nullable String namespaceUri) {
return (!StringUtils.hasLength(namespaceUri) || BEANS_NAMESPACE_URI.equals(namespaceUri));
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java
index 3411deb2c6..33a989d83a 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java
@@ -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.
@@ -52,7 +52,7 @@ public class BeansDtdResolver implements EntityResolver {
@Override
@Nullable
- public InputSource resolveEntity(String publicId, String systemId) throws IOException {
+ public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
if (logger.isTraceEnabled()) {
logger.trace("Trying to resolve XML entity with public ID [" + publicId +
"] and system ID [" + systemId + "]");
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
index 1f3382c93b..a7d900eb86 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java
@@ -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.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternUtils;
+import org.springframework.lang.Nullable;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
@@ -102,9 +103,10 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
}
/**
- * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} to pull the
- * source metadata from the supplied {@link Element}.
+ * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor}
+ * to pull the source metadata from the supplied {@link Element}.
*/
+ @Nullable
protected Object extractSource(Element ele) {
return getReaderContext().extractSource(ele);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java
index cf15a81132..7f1bd1b659 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java
@@ -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,7 @@ import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
+import org.springframework.lang.Nullable;
import org.springframework.util.xml.XmlValidationModeDetector;
/**
@@ -123,8 +124,8 @@ public class DefaultDocumentLoader implements DocumentLoader {
* @return the JAXP DocumentBuilder
* @throws ParserConfigurationException if thrown by JAXP methods
*/
- protected DocumentBuilder createDocumentBuilder(
- DocumentBuilderFactory factory, EntityResolver entityResolver, ErrorHandler errorHandler)
+ protected DocumentBuilder createDocumentBuilder(DocumentBuilderFactory factory,
+ @Nullable EntityResolver entityResolver, @Nullable ErrorHandler errorHandler)
throws ParserConfigurationException {
DocumentBuilder docBuilder = factory.newDocumentBuilder();
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java
index 030198636f..0b81b18309 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DelegatingEntityResolver.java
@@ -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.
@@ -79,7 +79,7 @@ public class DelegatingEntityResolver implements EntityResolver {
@Override
@Nullable
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
if (systemId != null) {
if (systemId.endsWith(DTD_SUFFIX)) {
return this.dtdResolver.resolveEntity(publicId, systemId);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java
index 930be05121..6fbb349656 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.springframework.beans.factory.xml;
import org.springframework.beans.factory.parsing.DefaultsDefinition;
+import org.springframework.lang.Nullable;
/**
* Simple JavaBean that holds the defaults specified at the {@code }
@@ -46,13 +47,14 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
/**
* Set the default lazy-init flag for the document that's currently parsed.
*/
- public void setLazyInit(String lazyInit) {
+ public void setLazyInit(@Nullable String lazyInit) {
this.lazyInit = lazyInit;
}
/**
* Return the default lazy-init flag for the document that's currently parsed.
*/
+ @Nullable
public String getLazyInit() {
return this.lazyInit;
}
@@ -60,13 +62,14 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
/**
* Set the default merge setting for the document that's currently parsed.
*/
- public void setMerge(String merge) {
+ public void setMerge(@Nullable String merge) {
this.merge = merge;
}
/**
* Return the default merge setting for the document that's currently parsed.
*/
+ @Nullable
public String getMerge() {
return this.merge;
}
@@ -74,13 +77,14 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
/**
* Set the default autowire setting for the document that's currently parsed.
*/
- public void setAutowire(String autowire) {
+ public void setAutowire(@Nullable String autowire) {
this.autowire = autowire;
}
/**
* Return the default autowire setting for the document that's currently parsed.
*/
+ @Nullable
public String getAutowire() {
return this.autowire;
}
@@ -89,7 +93,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
* Set the default autowire-candidate pattern for the document that's currently parsed.
* Also accepts a comma-separated list of patterns.
*/
- public void setAutowireCandidates(String autowireCandidates) {
+ public void setAutowireCandidates(@Nullable String autowireCandidates) {
this.autowireCandidates = autowireCandidates;
}
@@ -97,6 +101,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
* Return the default autowire-candidate pattern for the document that's currently parsed.
* May also return a comma-separated list of patterns.
*/
+ @Nullable
public String getAutowireCandidates() {
return this.autowireCandidates;
}
@@ -104,13 +109,14 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
/**
* Set the default init-method setting for the document that's currently parsed.
*/
- public void setInitMethod(String initMethod) {
+ public void setInitMethod(@Nullable String initMethod) {
this.initMethod = initMethod;
}
/**
* Return the default init-method setting for the document that's currently parsed.
*/
+ @Nullable
public String getInitMethod() {
return this.initMethod;
}
@@ -118,13 +124,14 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
/**
* Set the default destroy-method setting for the document that's currently parsed.
*/
- public void setDestroyMethod(String destroyMethod) {
+ public void setDestroyMethod(@Nullable String destroyMethod) {
this.destroyMethod = destroyMethod;
}
/**
* Return the default destroy-method setting for the document that's currently parsed.
*/
+ @Nullable
public String getDestroyMethod() {
return this.destroyMethod;
}
@@ -133,11 +140,12 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition {
* Set the configuration source {@code Object} for this metadata element.
* The exact type of the object will depend on the configuration mechanism used.
*/
- public void setSource(Object source) {
+ public void setSource(@Nullable Object source) {
this.source = source;
}
@Override
+ @Nullable
public Object getSource() {
return this.source;
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java
index bfa0529b3e..0fb89d87ae 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandler.java
@@ -91,6 +91,7 @@ public interface NamespaceHandler {
* A {@code null} value is strictly speaking invalid, but will be leniently
* treated like the case where the original bean definition gets returned.
*/
+ @Nullable
BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java
index ec83888539..4869d09527 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java
@@ -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.
@@ -25,6 +25,7 @@ import org.w3c.dom.Node;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.lang.Nullable;
/**
* Support class for implementing custom {@link NamespaceHandler NamespaceHandlers}.
@@ -47,22 +48,19 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
* Stores the {@link BeanDefinitionParser} implementations keyed by the
* local name of the {@link Element Elements} they handle.
*/
- private final Map parsers =
- new HashMap<>();
+ private final Map parsers = new HashMap<>();
/**
* Stores the {@link BeanDefinitionDecorator} implementations keyed by the
* local name of the {@link Element Elements} they handle.
*/
- private final Map decorators =
- new HashMap<>();
+ private final Map decorators = new HashMap<>();
/**
* Stores the {@link BeanDefinitionDecorator} implementations keyed by the local
* name of the {@link Attr Attrs} they handle.
*/
- private final Map attributeDecorators =
- new HashMap<>();
+ private final Map attributeDecorators = new HashMap<>();
/**
@@ -71,13 +69,15 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
*/
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
- return findParserForElement(element, parserContext).parse(element, parserContext);
+ BeanDefinitionParser parser = findParserForElement(element, parserContext);
+ return (parser != null ? parser.parse(element, parserContext) : null);
}
/**
* Locates the {@link BeanDefinitionParser} from the register implementations using
* the local name of the supplied {@link Element}.
*/
+ @Nullable
private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) {
String localName = parserContext.getDelegate().getLocalName(element);
BeanDefinitionParser parser = this.parsers.get(localName);
@@ -96,7 +96,8 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
public BeanDefinitionHolder decorate(
Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
- return findDecoratorForNode(node, parserContext).decorate(node, definition, parserContext);
+ BeanDefinitionDecorator decorator = findDecoratorForNode(node, parserContext);
+ return (decorator != null ? decorator.decorate(node, definition, parserContext) : null);
}
/**
@@ -104,6 +105,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
* the local name of the supplied {@link Node}. Supports both {@link Element Elements}
* and {@link Attr Attrs}.
*/
+ @Nullable
private BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) {
BeanDefinitionDecorator decorator = null;
String localName = parserContext.getDelegate().getLocalName(node);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
index 006d8bc7f9..9ef1709d24 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.parsing.ComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import org.springframework.lang.Nullable;
/**
* Context that gets passed along a bean definition parsing process,
@@ -53,7 +54,7 @@ public final class ParserContext {
}
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate,
- BeanDefinition containingBeanDefinition) {
+ @Nullable BeanDefinition containingBeanDefinition) {
this.readerContext = readerContext;
this.delegate = delegate;
@@ -85,6 +86,7 @@ public final class ParserContext {
return BeanDefinitionParserDelegate.TRUE_VALUE.equals(this.delegate.getDefaults().getLazyInit());
}
+ @Nullable
public Object extractSource(Object sourceCandidate) {
return this.readerContext.extractSource(sourceCandidate);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java
index a56dc16f07..660257cb69 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,7 +103,7 @@ public class PluggableSchemaResolver implements EntityResolver {
@Override
@Nullable
- public InputSource resolveEntity(String publicId, String systemId) throws IOException {
+ public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
if (logger.isTraceEnabled()) {
logger.trace("Trying to resolve XML entity with public id [" + publicId +
"] and system id [" + systemId + "]");
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java
index c9108541c5..2882ac7ce3 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java
@@ -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.
@@ -28,6 +28,7 @@ import org.xml.sax.SAXException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import org.springframework.lang.Nullable;
/**
* EntityResolver implementation that tries to resolve entity references
@@ -70,7 +71,7 @@ public class ResourceEntityResolver extends DelegatingEntityResolver {
@Override
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
InputSource source = super.resolveEntity(publicId, systemId);
if (source == null && systemId != null) {
String resourcePath = null;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java
index 420e10f27a..3f30514698 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java
@@ -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.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
index 384543fbec..48b30cc6d2 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
-
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
@@ -199,7 +198,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* which exhibits fail fast behaviour. External tools can provide an alternative implementation
* that collates errors and warnings for display in the tool UI.
*/
- public void setProblemReporter(ProblemReporter problemReporter) {
+ public void setProblemReporter(@Nullable ProblemReporter problemReporter) {
this.problemReporter = (problemReporter != null ? problemReporter : new FailFastProblemReporter());
}
@@ -209,7 +208,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* External tools can provide an alternative implementation to monitor the components being
* registered in the BeanFactory.
*/
- public void setEventListener(ReaderEventListener eventListener) {
+ public void setEventListener(@Nullable ReaderEventListener eventListener) {
this.eventListener = (eventListener != null ? eventListener : new EmptyReaderEventListener());
}
@@ -219,7 +218,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* as the source object. This means that - during normal runtime execution -
* no additional source metadata is attached to the bean configuration metadata.
*/
- public void setSourceExtractor(SourceExtractor sourceExtractor) {
+ public void setSourceExtractor(@Nullable SourceExtractor sourceExtractor) {
this.sourceExtractor = (sourceExtractor != null ? sourceExtractor : new NullSourceExtractor());
}
@@ -228,7 +227,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* If none is specified, a default instance will be created through
* {@link #createDefaultNamespaceHandlerResolver()}.
*/
- public void setNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver) {
+ public void setNamespaceHandlerResolver(@Nullable NamespaceHandlerResolver namespaceHandlerResolver) {
this.namespaceHandlerResolver = namespaceHandlerResolver;
}
@@ -237,7 +236,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
*
The default implementation is {@link DefaultDocumentLoader}
* which loads {@link Document} instances using JAXP.
*/
- public void setDocumentLoader(DocumentLoader documentLoader) {
+ public void setDocumentLoader(@Nullable DocumentLoader documentLoader) {
this.documentLoader = (documentLoader != null ? documentLoader : new DefaultDocumentLoader());
}
@@ -246,7 +245,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
*
By default, {@link ResourceEntityResolver} will be used. Can be overridden
* for custom entity resolution, for example relative to some specific base path.
*/
- public void setEntityResolver(EntityResolver entityResolver) {
+ public void setEntityResolver(@Nullable EntityResolver entityResolver) {
this.entityResolver = entityResolver;
}
@@ -286,11 +285,7 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
*
The default is {@link DefaultBeanDefinitionDocumentReader}.
* @param documentReaderClass the desired BeanDefinitionDocumentReader implementation class
*/
- public void setDocumentReaderClass(Class> documentReaderClass) {
- if (documentReaderClass == null || !BeanDefinitionDocumentReader.class.isAssignableFrom(documentReaderClass)) {
- throw new IllegalArgumentException(
- "documentReaderClass must be an implementation of the BeanDefinitionDocumentReader interface");
- }
+ public void setDocumentReaderClass(Class extends BeanDefinitionDocumentReader> documentReaderClass) {
this.documentReaderClass = documentReaderClass;
}
@@ -545,7 +540,8 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader {
* Default implementation returns an instance of {@link DefaultNamespaceHandlerResolver}.
*/
protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() {
- return new DefaultNamespaceHandlerResolver(getResourceLoader().getClassLoader());
+ ClassLoader cl = (getResourceLoader() != null ? getResourceLoader().getClassLoader() : getBeanClassLoader());
+ return new DefaultNamespaceHandlerResolver(cl);
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java
index 4366c641e0..139b0b59a0 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
+import org.springframework.lang.Nullable;
/**
* Extension of {@link org.springframework.beans.factory.parsing.ReaderContext},
@@ -67,10 +68,12 @@ public class XmlReaderContext extends ReaderContext {
return this.reader.getRegistry();
}
+ @Nullable
public final ResourceLoader getResourceLoader() {
return this.reader.getResourceLoader();
}
+ @Nullable
public final ClassLoader getBeanClassLoader() {
return this.reader.getBeanClassLoader();
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java
index 9461c1fcdf..57a7158c43 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
+
/**
* Editor for byte arrays. Strings will simply be converted to
* their corresponding byte representations.
@@ -29,7 +31,7 @@ import java.beans.PropertyEditorSupport;
public class ByteArrayPropertyEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) {
+ public void setAsText(@Nullable String text) {
setValue(text != null ? text.getBytes() : null);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java
index 32b76c5f2e..7a3636f8ec 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
+
/**
* Editor for char arrays. Strings will simply be converted to
* their corresponding char representations.
@@ -29,7 +31,7 @@ import java.beans.PropertyEditorSupport;
public class CharArrayPropertyEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) {
+ public void setAsText(@Nullable String text) {
setValue(text != null ? text.toCharArray() : null);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java
index d5a791a1ce..0465556a70 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java
@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -69,7 +70,7 @@ public class CharacterEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) throws IllegalArgumentException {
+ public void setAsText(@Nullable String text) throws IllegalArgumentException {
if (this.allowEmpty && !StringUtils.hasLength(text)) {
// Treat empty String as null value.
setValue(null);
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java
index 1bdd2c7630..ed0e513ac3 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java
@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -89,7 +90,7 @@ public class CustomBooleanEditor extends PropertyEditorSupport {
* @see #VALUE_YES
* @see #VALUE_NO
*/
- public CustomBooleanEditor(String trueString, String falseString, boolean allowEmpty) {
+ public CustomBooleanEditor(@Nullable String trueString, @Nullable String falseString, boolean allowEmpty) {
this.trueString = trueString;
this.falseString = falseString;
this.allowEmpty = allowEmpty;
@@ -97,7 +98,7 @@ public class CustomBooleanEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) throws IllegalArgumentException {
+ public void setAsText(@Nullable String text) throws IllegalArgumentException {
String input = (text != null ? text.trim() : null);
if (this.allowEmpty && !StringUtils.hasLength(input)) {
// Treat empty String as null value.
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java
index 303612b465..d8f4839bc6 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomCollectionEditor.java
@@ -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.
@@ -26,6 +26,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
@@ -86,9 +87,7 @@ public class CustomCollectionEditor extends PropertyEditorSupport {
*/
@SuppressWarnings("rawtypes")
public CustomCollectionEditor(Class extends Collection> collectionType, boolean nullAsEmptyCollection) {
- if (collectionType == null) {
- throw new IllegalArgumentException("Collection type is required");
- }
+ Assert.notNull(collectionType, "Collection type is required");
if (!Collection.class.isAssignableFrom(collectionType)) {
throw new IllegalArgumentException(
"Collection type [" + collectionType.getName() + "] does not implement [java.util.Collection]");
@@ -110,7 +109,7 @@ public class CustomCollectionEditor extends PropertyEditorSupport {
* Convert the given value to a Collection of the target type.
*/
@Override
- public void setValue(Object value) {
+ public void setValue(@Nullable Object value) {
if (value == null && this.nullAsEmptyCollection) {
super.setValue(createCollection(this.collectionType, 0));
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java
index 674e7422fe..140ccc1418 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java
@@ -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.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -94,7 +95,7 @@ public class CustomDateEditor extends PropertyEditorSupport {
* Parse the Date from the given text, using the specified DateFormat.
*/
@Override
- public void setAsText(String text) throws IllegalArgumentException {
+ public void setAsText(@Nullable String text) throws IllegalArgumentException {
if (this.allowEmpty && !StringUtils.hasText(text)) {
// Treat empty String as null value.
setValue(null);
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java
index 1f85ee721e..0dd7ee2859 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomMapEditor.java
@@ -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.
@@ -23,6 +23,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
/**
@@ -76,9 +77,7 @@ public class CustomMapEditor extends PropertyEditorSupport {
*/
@SuppressWarnings("rawtypes")
public CustomMapEditor(Class extends Map> mapType, boolean nullAsEmptyMap) {
- if (mapType == null) {
- throw new IllegalArgumentException("Map type is required");
- }
+ Assert.notNull(mapType, "Map type is required");
if (!Map.class.isAssignableFrom(mapType)) {
throw new IllegalArgumentException(
"Map type [" + mapType.getName() + "] does not implement [java.util.Map]");
@@ -100,7 +99,7 @@ public class CustomMapEditor extends PropertyEditorSupport {
* Convert the given value to a Map of the target type.
*/
@Override
- public void setValue(Object value) {
+ public void setValue(@Nullable Object value) {
if (value == null && this.nullAsEmptyMap) {
super.setValue(createMap(this.mapType, 0));
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java
index 890788c353..aad392d15c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java
@@ -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.
@@ -19,6 +19,7 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
import java.text.NumberFormat;
+import org.springframework.lang.Nullable;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
@@ -84,9 +85,9 @@ public class CustomNumberEditor extends PropertyEditorSupport {
* @see java.text.NumberFormat#format
*/
public CustomNumberEditor(Class extends Number> numberClass,
- NumberFormat numberFormat, boolean allowEmpty) throws IllegalArgumentException {
+ @Nullable NumberFormat numberFormat, boolean allowEmpty) throws IllegalArgumentException {
- if (numberClass == null || !Number.class.isAssignableFrom(numberClass)) {
+ if (!Number.class.isAssignableFrom(numberClass)) {
throw new IllegalArgumentException("Property class must be a subclass of Number");
}
this.numberClass = numberClass;
@@ -118,7 +119,7 @@ public class CustomNumberEditor extends PropertyEditorSupport {
* Coerce a Number value into the required target class, if necessary.
*/
@Override
- public void setValue(Object value) {
+ public void setValue(@Nullable Object value) {
if (value instanceof Number) {
super.setValue(NumberUtils.convertNumberToTargetClass((Number) value, this.numberClass));
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java
index 0c4c971fea..6d36f06b4c 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java
@@ -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.
@@ -19,6 +19,8 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
import java.util.regex.Pattern;
+import org.springframework.lang.Nullable;
+
/**
* Editor for {@code java.util.regex.Pattern}, to directly populate a Pattern property.
* Expects the same syntax as Pattern's {@code compile} method.
@@ -56,7 +58,7 @@ public class PatternEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) {
+ public void setAsText(@Nullable String text) {
setValue(text != null ? Pattern.compile(text, this.flags) : null);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java
index 4615e8ffb4..9bbdb8e885 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java
@@ -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.
@@ -23,6 +23,8 @@ import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
+import org.springframework.lang.Nullable;
+
/**
* Custom {@link java.beans.PropertyEditor} for {@link Properties} objects.
*
@@ -45,7 +47,7 @@ public class PropertiesEditor extends PropertyEditorSupport {
* @param text the text to be so converted
*/
@Override
- public void setAsText(String text) throws IllegalArgumentException {
+ public void setAsText(@Nullable String text) throws IllegalArgumentException {
Properties props = new Properties();
if (text != null) {
try {
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
index 7eabc102b7..5ec38eb7dc 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
@@ -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.
@@ -96,8 +96,7 @@ public class ResourceBundleEditor extends PropertyEditorSupport {
}
String localeString = name.substring(separator + 1);
Locale locale = StringUtils.parseLocaleString(localeString);
- setValue((StringUtils.hasText(localeString)) ? ResourceBundle.getBundle(baseName, locale) :
- ResourceBundle.getBundle(baseName));
+ setValue(locale != null ? ResourceBundle.getBundle(baseName, locale) : ResourceBundle.getBundle(baseName));
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java
index 85adf51567..5d88f30b33 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java
@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -99,7 +100,7 @@ public class StringArrayPropertyEditor extends PropertyEditorSupport {
* @param emptyArrayAsNull {@code true} if an empty String array
* is to be transformed into {@code null}
*/
- public StringArrayPropertyEditor(String separator, String charsToDelete, boolean emptyArrayAsNull) {
+ public StringArrayPropertyEditor(String separator, @Nullable String charsToDelete, boolean emptyArrayAsNull) {
this(separator, charsToDelete, emptyArrayAsNull, true);
}
@@ -114,7 +115,9 @@ public class StringArrayPropertyEditor extends PropertyEditorSupport {
* @param trimValues {@code true} if the values in the parsed arrays
* are to be trimmed of whitespace (default is true).
*/
- public StringArrayPropertyEditor(String separator, String charsToDelete, boolean emptyArrayAsNull, boolean trimValues) {
+ public StringArrayPropertyEditor(
+ String separator, @Nullable String charsToDelete, boolean emptyArrayAsNull, boolean trimValues) {
+
this.separator = separator;
this.charsToDelete = charsToDelete;
this.emptyArrayAsNull = emptyArrayAsNull;
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java
index c61ff722d7..cb1cd0e13b 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java
@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.beans.propertyeditors;
import java.beans.PropertyEditorSupport;
+import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -61,7 +62,7 @@ public class StringTrimmerEditor extends PropertyEditorSupport {
@Override
- public void setAsText(String text) {
+ public void setAsText(@Nullable String text) {
if (text == null) {
setValue(null);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java b/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java
index 72912d5e32..84e854d90e 100644
--- a/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java
+++ b/spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java
@@ -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.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.TypeMismatchException;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
import org.springframework.util.MethodInvoker;
import org.springframework.util.ReflectionUtils;
@@ -65,6 +66,7 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
* (provided that the present TypeConverter actually implements the
* PropertyEditorRegistry interface).
*/
+ @Nullable
public TypeConverter getTypeConverter() {
if (this.typeConverter == null && this.useDefaultConverter) {
this.typeConverter = getDefaultTypeConverter();
@@ -135,7 +137,9 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
String targetMethod = getTargetMethod();
Method matchingMethod = null;
int argCount = arguments.length;
- Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass());
+ Class> targetClass = getTargetClass();
+ Assert.state(targetClass != null, "No target class set");
+ Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass);
int minTypeDiffWeight = Integer.MAX_VALUE;
Object[] argumentsToUse = null;
for (Method candidate : candidates) {
diff --git a/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java b/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java
index cf7481a78d..d22b26ae0b 100644
--- a/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java
+++ b/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java
@@ -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.ArrayList;
import java.util.Date;
import java.util.List;
+import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -122,6 +123,7 @@ public class PagedListHolder