Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,10 +56,10 @@ import org.springframework.util.StringUtils;
|
||||
* as String arrays are converted in such a format if the array itself is not
|
||||
* assignable.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Stephane Nicoll
|
||||
* @author Rod Johnson
|
||||
* @author Rob Harrop
|
||||
* @since 4.2
|
||||
* @see #registerCustomEditor
|
||||
* @see #setPropertyValues
|
||||
@@ -189,7 +189,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
* @param nestedPath the nested path of the object
|
||||
* @param rootObject the root object at the top of the path
|
||||
*/
|
||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
||||
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
||||
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||
@@ -199,11 +199,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
public final Object getWrappedInstance() {
|
||||
Assert.state(this.wrappedObject != null, "No wrapped instance");
|
||||
return this.wrappedObject;
|
||||
}
|
||||
|
||||
public final Class<?> getWrappedClass() {
|
||||
return (this.wrappedObject != null ? this.wrappedObject.getClass() : null);
|
||||
return getWrappedInstance().getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,6 +218,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
* Return the root object at the top of the path of this accessor.
|
||||
* @see #getNestedPath
|
||||
*/
|
||||
@Nullable
|
||||
public final Object getRootInstance() {
|
||||
return this.rootObject;
|
||||
}
|
||||
@@ -226,11 +228,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
* @see #getNestedPath
|
||||
*/
|
||||
public final Class<?> getRootClass() {
|
||||
return (this.rootObject != null ? this.rootObject.getClass() : null);
|
||||
Assert.state(this.wrappedObject != null, "No root object");
|
||||
return this.rootObject.getClass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPropertyValue(String propertyName, Object value) throws BeansException {
|
||||
public void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException {
|
||||
AbstractNestablePropertyAccessor nestedPa;
|
||||
try {
|
||||
nestedPa = getPropertyAccessorForPropertyPath(propertyName);
|
||||
@@ -279,10 +282,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
@SuppressWarnings("unchecked")
|
||||
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
|
||||
Object propValue = getPropertyHoldingValue(tokens);
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
if (ph == null) {
|
||||
throw new InvalidPropertyException(
|
||||
getRootClass(), this.nestedPath + tokens.actualName, "No property handler found");
|
||||
}
|
||||
String lastKey = tokens.keys[tokens.keys.length - 1];
|
||||
|
||||
if (propValue.getClass().isArray()) {
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
Class<?> requiredType = propValue.getClass().getComponentType();
|
||||
int arrayIndex = Integer.parseInt(lastKey);
|
||||
Object oldValue = null;
|
||||
@@ -309,7 +316,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
else if (propValue instanceof List) {
|
||||
PropertyHandler ph = getPropertyHandler(tokens.actualName);
|
||||
Class<?> requiredType = ph.getCollectionType(tokens.keys.length);
|
||||
List<Object> list = (List<Object>) propValue;
|
||||
int index = Integer.parseInt(lastKey);
|
||||
@@ -346,7 +352,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
else if (propValue instanceof Map) {
|
||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||
Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length);
|
||||
Class<?> mapValueType = ph.getMapValueType(tokens.keys.length);
|
||||
Map<Object, Object> map = (Map<Object, Object>) propValue;
|
||||
@@ -449,7 +454,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
|
||||
}
|
||||
ph.setValue(this.wrappedObject, valueToApply);
|
||||
ph.setValue(valueToApply);
|
||||
}
|
||||
catch (TypeMismatchException ex) {
|
||||
throw ex;
|
||||
@@ -567,34 +572,29 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
return false;
|
||||
}
|
||||
|
||||
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, Class<?> requiredType,
|
||||
TypeDescriptor td) throws TypeMismatchException {
|
||||
@Nullable
|
||||
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||
@Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable TypeDescriptor td)
|
||||
throws TypeMismatchException {
|
||||
|
||||
try {
|
||||
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
|
||||
}
|
||||
catch (ConverterNotFoundException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new ConversionNotSupportedException(pce, td.getType(), ex);
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new TypeMismatchException(pce, requiredType, ex);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new ConversionNotSupportedException(pce, requiredType, ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConversionException | IllegalArgumentException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||
throw new TypeMismatchException(pce, requiredType, ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object convertForProperty(String propertyName, @Nullable Object oldValue, Object newValue, TypeDescriptor td)
|
||||
@Nullable
|
||||
protected Object convertForProperty(
|
||||
String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
|
||||
@@ -608,6 +608,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
||||
String propertyName = tokens.canonicalName;
|
||||
String actualName = tokens.actualName;
|
||||
@@ -724,10 +725,10 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link PropertyHandler} for the specified local {@code propertyName}. Only
|
||||
* used to reach a property available in the current context.
|
||||
* Return a {@link PropertyHandler} for the specified local {@code propertyName}.
|
||||
* Only used to reach a property available in the current context.
|
||||
* @param propertyName the name of a local property
|
||||
* @return the handler for that property or {@code null} if it has not been found
|
||||
* @return the handler for that property, or {@code null} if it has not been found
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
|
||||
@@ -760,7 +761,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
Array.set(newArray, i, newValue(componentType, null, name));
|
||||
}
|
||||
setPropertyValue(name, newArray);
|
||||
return getPropertyValue(name);
|
||||
Object defaultValue = getPropertyValue(name);
|
||||
Assert.state(defaultValue != null, "Default value must not be null");
|
||||
return defaultValue;
|
||||
}
|
||||
else {
|
||||
return array;
|
||||
@@ -872,17 +875,18 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
private Object setDefaultValue(PropertyTokenHolder tokens) {
|
||||
PropertyValue pv = createDefaultPropertyValue(tokens);
|
||||
setPropertyValue(tokens, pv);
|
||||
return getPropertyValue(tokens);
|
||||
Object defaultValue = getPropertyValue(tokens);
|
||||
Assert.state(defaultValue != null, "Default value must not be null");
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private PropertyValue createDefaultPropertyValue(PropertyTokenHolder tokens) {
|
||||
TypeDescriptor desc = getPropertyTypeDescriptor(tokens.canonicalName);
|
||||
Class<?> type = desc.getType();
|
||||
if (type == null) {
|
||||
if (desc == null) {
|
||||
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
|
||||
"Could not determine property type for auto-growing a default value");
|
||||
}
|
||||
Object defaultValue = newValue(type, desc, tokens.canonicalName);
|
||||
Object defaultValue = newValue(desc.getType(), desc, tokens.canonicalName);
|
||||
return new PropertyValue(tokens.canonicalName, defaultValue);
|
||||
}
|
||||
|
||||
@@ -1005,24 +1009,28 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||
|
||||
public abstract ResolvableType getResolvableType();
|
||||
|
||||
@Nullable
|
||||
public Class<?> getMapKeyType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(0);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> getMapValueType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<?> getCollectionType(int nestingLevel) {
|
||||
return getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract TypeDescriptor nested(int level);
|
||||
|
||||
@Nullable
|
||||
public abstract Object getValue() throws Exception;
|
||||
|
||||
public abstract void setValue(Object object, Object value) throws Exception;
|
||||
public abstract void setValue(@Nullable Object value) throws Exception;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the {@link PropertyAccessor} interface.
|
||||
* Provides base implementations of all convenience methods, with the
|
||||
@@ -151,6 +153,6 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
||||
* accessor method failed or a type mismatch occurred
|
||||
*/
|
||||
@Override
|
||||
public abstract void setPropertyValue(String propertyName, Object value) throws BeansException;
|
||||
public abstract void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,7 +53,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeanInstantiationException(Class<?> beanClass, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Class<?> beanClass, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
|
||||
this.beanClass = beanClass;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
* @param cause the root cause
|
||||
* @since 4.3
|
||||
*/
|
||||
public BeanInstantiationException(Constructor<?> constructor, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Constructor<?> constructor, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructor.getDeclaringClass();
|
||||
this.constructor = constructor;
|
||||
@@ -79,7 +79,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
* @param cause the root cause
|
||||
* @since 4.3
|
||||
*/
|
||||
public BeanInstantiationException(Method constructingMethod, String msg, Throwable cause) {
|
||||
public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructingMethod.getReturnType();
|
||||
this.constructingMethod = constructingMethod;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -40,7 +41,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
||||
* @param name the name of the attribute (never {@code null})
|
||||
* @param value the value of the attribute (possibly before type conversion)
|
||||
*/
|
||||
public BeanMetadataAttribute(String name, Object value) {
|
||||
public BeanMetadataAttribute(String name, @Nullable Object value) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
@@ -65,7 +66,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -426,7 +426,7 @@ public abstract class BeanUtils {
|
||||
* @return the corresponding editor, or {@code null} if none found
|
||||
*/
|
||||
@Nullable
|
||||
public static PropertyEditor findEditorByConvention(Class<?> targetType) {
|
||||
public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetType) {
|
||||
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
|
||||
return null;
|
||||
}
|
||||
@@ -476,7 +476,7 @@ public abstract class BeanUtils {
|
||||
* @param beanClasses the classes to check against
|
||||
* @return the property type, or {@code Object.class} as fallback
|
||||
*/
|
||||
public static Class<?> findPropertyType(String propertyName, Class<?>... beanClasses) {
|
||||
public static Class<?> findPropertyType(String propertyName, @Nullable Class<?>... beanClasses) {
|
||||
if (beanClasses != null) {
|
||||
for (Class<?> beanClass : beanClasses) {
|
||||
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
|
||||
@@ -599,8 +599,8 @@ public abstract class BeanUtils {
|
||||
* @throws BeansException if the copying failed
|
||||
* @see BeanWrapper
|
||||
*/
|
||||
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, String... ignoreProperties)
|
||||
throws BeansException {
|
||||
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
|
||||
@Nullable String... ignoreProperties) throws BeansException {
|
||||
|
||||
Assert.notNull(source, "Source must not be null");
|
||||
Assert.notNull(target, "Target must not be null");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,6 @@ package org.springframework.beans;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* The central interface of Spring's low-level JavaBeans infrastructure.
|
||||
*
|
||||
@@ -64,18 +62,13 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
|
||||
int getAutoGrowCollectionLimit();
|
||||
|
||||
/**
|
||||
* Return the bean instance wrapped by this object, if any.
|
||||
* @return the bean instance, or {@code null} if none set
|
||||
* Return the bean instance wrapped by this object.
|
||||
*/
|
||||
@Nullable
|
||||
Object getWrappedInstance();
|
||||
|
||||
/**
|
||||
* Return the type of the wrapped JavaBean object.
|
||||
* @return the type of the wrapped bean instance,
|
||||
* or {@code null} if no wrapped object has been set
|
||||
* Return the type of the wrapped bean instance.
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getWrappedClass();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.beans;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.convert.Property;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Default {@link BeanWrapper} implementation that should be sufficient
|
||||
@@ -148,7 +147,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
||||
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||
super.setWrappedInstance(object, nestedPath, rootObject);
|
||||
setIntrospectionClass(getWrappedClass());
|
||||
}
|
||||
@@ -169,7 +168,6 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||
* for the wrapped object.
|
||||
*/
|
||||
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
||||
Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
|
||||
if (this.cachedIntrospectionResults == null) {
|
||||
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
||||
}
|
||||
@@ -203,6 +201,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||
* @return the new value, possibly the result of type conversion
|
||||
* @throws TypeMismatchException if type conversion failed
|
||||
*/
|
||||
@Nullable
|
||||
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
|
||||
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
|
||||
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
|
||||
@@ -289,73 +288,45 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||
@Override
|
||||
public Object getValue() throws Exception {
|
||||
final Method readMethod = this.pd.getReadMethod();
|
||||
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
readMethod.setAccessible(true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
readMethod.setAccessible(true);
|
||||
}
|
||||
}
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(readMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
||||
}
|
||||
}, acc);
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
readMethod.invoke(getWrappedInstance(), (Object[]) null), acc);
|
||||
}
|
||||
catch (PrivilegedActionException pae) {
|
||||
throw pae.getException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReflectionUtils.makeAccessible(readMethod);
|
||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(final Object object, Object valueToApply) throws Exception {
|
||||
public void setValue(final @Nullable Object value) throws Exception {
|
||||
final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?
|
||||
((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :
|
||||
this.pd.getWriteMethod());
|
||||
if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers()) && !writeMethod.isAccessible()) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
writeMethod.setAccessible(true);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
writeMethod.setAccessible(true);
|
||||
}
|
||||
}
|
||||
final Object value = valueToApply;
|
||||
if (System.getSecurityManager() != null) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(writeMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
writeMethod.invoke(object, value);
|
||||
return null;
|
||||
}
|
||||
}, acc);
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
writeMethod.invoke(getWrappedInstance(), value), acc);
|
||||
}
|
||||
catch (PrivilegedActionException ex) {
|
||||
throw ex.getException();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReflectionUtils.makeAccessible(writeMethod);
|
||||
writeMethod.invoke(getWrappedInstance(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract superclass for all exceptions thrown in the beans package
|
||||
@@ -46,27 +46,8 @@ public abstract class BeansException extends NestedRuntimeException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeansException(String msg, Throwable cause) {
|
||||
public BeansException(@Nullable String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof BeansException)) {
|
||||
return false;
|
||||
}
|
||||
BeansException otherBe = (BeansException) other;
|
||||
return (getMessage().equals(otherBe.getMessage()) &&
|
||||
ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getMessage().hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -136,7 +137,7 @@ public class CachedIntrospectionResults {
|
||||
* be paired with a {@link #clearClassLoader} call at application shutdown.
|
||||
* @param classLoader the ClassLoader to accept
|
||||
*/
|
||||
public static void acceptClassLoader(ClassLoader classLoader) {
|
||||
public static void acceptClassLoader(@Nullable ClassLoader classLoader) {
|
||||
if (classLoader != null) {
|
||||
acceptedClassLoaders.add(classLoader);
|
||||
}
|
||||
@@ -148,7 +149,7 @@ public class CachedIntrospectionResults {
|
||||
* removing the ClassLoader (and its children) from the acceptance list.
|
||||
* @param classLoader the ClassLoader to clear the cache for
|
||||
*/
|
||||
public static void clearClassLoader(ClassLoader classLoader) {
|
||||
public static void clearClassLoader(@Nullable ClassLoader classLoader) {
|
||||
for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = it.next();
|
||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||
@@ -226,7 +227,7 @@ public class CachedIntrospectionResults {
|
||||
* @param candidate the candidate ClassLoader to check
|
||||
* @param parent the parent ClassLoader to check for
|
||||
*/
|
||||
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
|
||||
private static boolean isUnderneathClassLoader(@Nullable ClassLoader candidate, @Nullable ClassLoader parent) {
|
||||
if (candidate == parent) {
|
||||
return true;
|
||||
}
|
||||
@@ -336,6 +337,7 @@ public class CachedIntrospectionResults {
|
||||
return this.beanInfo.getBeanDescriptor().getBeanClass();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
PropertyDescriptor getPropertyDescriptor(String name) {
|
||||
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
|
||||
if (pd == null && StringUtils.hasLength(name)) {
|
||||
@@ -375,6 +377,7 @@ public class CachedIntrospectionResults {
|
||||
return (existing != null ? existing : td);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {
|
||||
return this.typeDescriptorCache.get(pd);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property
|
||||
* Specify a Spring 3.0 ConversionService to use for converting
|
||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
*/
|
||||
void setConversionService(ConversionService conversionService);
|
||||
void setConversionService(@Nullable ConversionService conversionService);
|
||||
|
||||
/**
|
||||
* Return the associated ConversionService, if any.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -134,10 +134,10 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object object, Object value) throws Exception {
|
||||
public void setValue(Object value) throws Exception {
|
||||
try {
|
||||
ReflectionUtils.makeAccessible(this.field);
|
||||
this.field.set(object, value);
|
||||
this.field.set(getWrappedInstance(), value);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Thrown on an unrecoverable problem encountered in the
|
||||
* beans packages or sub-packages, e.g. bad class or field.
|
||||
@@ -39,7 +41,7 @@ public class FatalBeanException extends BeansException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public FatalBeanException(String msg, Throwable cause) {
|
||||
public FatalBeanException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -57,18 +58,14 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
|
||||
|
||||
|
||||
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
|
||||
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
|
||||
@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
|
||||
throws IntrospectionException {
|
||||
|
||||
super(propertyName, null, null);
|
||||
|
||||
if (beanClass == null) {
|
||||
throw new IntrospectionException("Bean class must not be null");
|
||||
}
|
||||
this.beanClass = beanClass;
|
||||
|
||||
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
|
||||
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
|
||||
Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
|
||||
Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
|
||||
if (writeMethodToUse == null && readMethodToUse != null) {
|
||||
// Fallback: Original JavaBeans introspection might not have found matching setter
|
||||
// method due to lack of bridge method resolution, in case of the getter using a
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when referring to an invalid bean property.
|
||||
* Carries the offending bean class and property name.
|
||||
@@ -48,7 +50,7 @@ public class InvalidPropertyException extends FatalBeanException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, Throwable cause) {
|
||||
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, @Nullable Throwable cause) {
|
||||
super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
|
||||
this.beanClass = beanClass;
|
||||
this.propertyName = propertyName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* @param original the PropertyValues to copy
|
||||
* @see #addPropertyValues(PropertyValues)
|
||||
*/
|
||||
public MutablePropertyValues(PropertyValues original) {
|
||||
public MutablePropertyValues(@Nullable PropertyValues original) {
|
||||
// We can optimize this because it's all new:
|
||||
// There is no replacement of existing property values.
|
||||
if (original != null) {
|
||||
@@ -82,7 +82,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* @param original Map with property values keyed by property name Strings
|
||||
* @see #addPropertyValues(Map)
|
||||
*/
|
||||
public MutablePropertyValues(Map<?, ?> original) {
|
||||
public MutablePropertyValues(@Nullable Map<?, ?> original) {
|
||||
// We can optimize this because it's all new:
|
||||
// There is no replacement of existing property values.
|
||||
if (original != null) {
|
||||
@@ -103,7 +103,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* It is not intended for typical programmatic use.
|
||||
* @param propertyValueList List of PropertyValue objects
|
||||
*/
|
||||
public MutablePropertyValues(List<PropertyValue> propertyValueList) {
|
||||
public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) {
|
||||
this.propertyValueList =
|
||||
(propertyValueList != null ? propertyValueList : new ArrayList<>());
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* @param other the PropertyValues to copy
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues addPropertyValues(PropertyValues other) {
|
||||
public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {
|
||||
if (other != null) {
|
||||
PropertyValue[] pvs = other.getPropertyValues();
|
||||
for (PropertyValue pv : pvs) {
|
||||
@@ -149,7 +149,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* which must be a String
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues addPropertyValues(Map<?, ?> other) {
|
||||
public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {
|
||||
if (other != null) {
|
||||
for (Map.Entry<?, ?> entry : other.entrySet()) {
|
||||
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
|
||||
@@ -197,7 +197,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
* @param propertyValue value of the property
|
||||
* @return this in order to allow for adding multiple property values in a chain
|
||||
*/
|
||||
public MutablePropertyValues add(String propertyName, Object propertyValue) {
|
||||
public MutablePropertyValues add(String propertyName, @Nullable Object propertyValue) {
|
||||
addPropertyValue(new PropertyValue(propertyName, propertyValue));
|
||||
return this;
|
||||
}
|
||||
@@ -263,7 +263,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
/**
|
||||
* Get the raw property value, if any.
|
||||
* @param propertyName the name to search for
|
||||
* @return the raw property value, or {@code null}
|
||||
* @return the raw property value, or {@code null} if none found
|
||||
* @since 4.0
|
||||
* @see #getPropertyValue(String)
|
||||
* @see PropertyValue#getValue()
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, Throwable cause) {
|
||||
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.propertyChangeEvent = propertyChangeEvent;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public PropertyAccessException(String msg, Throwable cause) {
|
||||
public PropertyAccessException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||
/**
|
||||
* Return the name of the affected property, if available.
|
||||
*/
|
||||
@Nullable
|
||||
public String getPropertyName() {
|
||||
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,8 +82,6 @@ public interface PropertyAccessor {
|
||||
* (may be a nested path and/or an indexed/mapped property)
|
||||
* @return the property type for the particular property,
|
||||
* or {@code null} if not determinable
|
||||
* @throws InvalidPropertyException if there is no such property or
|
||||
* if the property isn't readable
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
@@ -97,8 +95,8 @@ public interface PropertyAccessor {
|
||||
* (may be a nested path and/or an indexed/mapped property)
|
||||
* @return the property type for the particular property,
|
||||
* or {@code null} if not determinable
|
||||
* @throws InvalidPropertyException if there is no such property or
|
||||
* if the property isn't readable
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
@Nullable
|
||||
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
|
||||
@@ -113,6 +111,7 @@ public interface PropertyAccessor {
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed
|
||||
*/
|
||||
@Nullable
|
||||
Object getPropertyValue(String propertyName) throws BeansException;
|
||||
|
||||
/**
|
||||
@@ -125,7 +124,7 @@ public interface PropertyAccessor {
|
||||
* @throws PropertyAccessException if the property was valid but the
|
||||
* accessor method failed or a type mismatch occurred
|
||||
*/
|
||||
void setPropertyValue(String propertyName, Object value) throws BeansException;
|
||||
void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||
|
||||
/**
|
||||
* Set the specified value as current property value.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Utility methods for classes that perform bean property access
|
||||
* according to the {@link PropertyAccessor} interface.
|
||||
@@ -42,7 +44,7 @@ public abstract class PropertyAccessorUtils {
|
||||
* @param propertyPath the property path to check
|
||||
* @return whether the path indicates an indexed or nested property
|
||||
*/
|
||||
public static boolean isNestedOrIndexedProperty(String propertyPath) {
|
||||
public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath) {
|
||||
if (propertyPath == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -137,7 +139,7 @@ public abstract class PropertyAccessorUtils {
|
||||
* @param propertyName the bean property path
|
||||
* @return the canonical representation of the property path
|
||||
*/
|
||||
public static String canonicalPropertyName(String propertyName) {
|
||||
public static String canonicalPropertyName(@Nullable String propertyName) {
|
||||
if (propertyName == null) {
|
||||
return "";
|
||||
}
|
||||
@@ -171,7 +173,8 @@ public abstract class PropertyAccessorUtils {
|
||||
* (as array of the same size)
|
||||
* @see #canonicalPropertyName(String)
|
||||
*/
|
||||
public static String[] canonicalPropertyNames(String[] propertyNames) {
|
||||
@Nullable
|
||||
public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) {
|
||||
if (propertyNames == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,7 +48,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
||||
* @param propertyAccessExceptions the List of PropertyAccessExceptions
|
||||
*/
|
||||
public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) {
|
||||
super(null);
|
||||
super(null, null);
|
||||
Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required");
|
||||
this.propertyAccessExceptions = propertyAccessExceptions;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Class<?> exType) {
|
||||
public boolean contains(@Nullable Class<?> exType) {
|
||||
if (exType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,10 @@ class PropertyDescriptorUtils {
|
||||
/**
|
||||
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
|
||||
*/
|
||||
public static Class<?> findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException {
|
||||
@Nullable
|
||||
public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
|
||||
throws IntrospectionException {
|
||||
|
||||
Class<?> propertyType = null;
|
||||
|
||||
if (readMethod != null) {
|
||||
@@ -103,8 +107,9 @@ class PropertyDescriptorUtils {
|
||||
/**
|
||||
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
|
||||
*/
|
||||
public static Class<?> findIndexedPropertyType(String name, Class<?> propertyType,
|
||||
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
||||
@Nullable
|
||||
public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
|
||||
@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {
|
||||
|
||||
Class<?> indexedPropertyType = null;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -112,7 +112,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* Specify a Spring 3.0 ConversionService to use for converting
|
||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
*/
|
||||
public void setConversionService(ConversionService conversionService) {
|
||||
public void setConversionService(@Nullable ConversionService conversionService) {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @return the custom editor, or {@code null} if none specific for this property
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor getCustomEditor(String propertyName, Class<?> requiredType) {
|
||||
private PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
|
||||
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
|
||||
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @see java.beans.PropertyEditor#getAsText()
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor getCustomEditor(Class<?> requiredType) {
|
||||
private PropertyEditor getCustomEditor(@Nullable Class<?> requiredType) {
|
||||
if (requiredType == null || this.customEditors == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -521,7 +521,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
|
||||
private final Class<?> registeredType;
|
||||
|
||||
private CustomEditorHolder(PropertyEditor propertyEditor, Class<?> registeredType) {
|
||||
private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class<?> registeredType) {
|
||||
this.propertyEditor = propertyEditor;
|
||||
this.registeredType = registeredType;
|
||||
}
|
||||
@@ -530,11 +530,12 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
return this.propertyEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Class<?> getRegisteredType() {
|
||||
return this.registeredType;
|
||||
}
|
||||
|
||||
private PropertyEditor getPropertyEditor(Class<?> requiredType) {
|
||||
private PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) {
|
||||
// Special case: If no required type specified, which usually only happens for
|
||||
// Collection elements, or required type is not assignable to registered type,
|
||||
// which usually only happens for generic properties of type Object -
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.beans;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -63,7 +64,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
* @param name the name of the property (never {@code null})
|
||||
* @param value the value of the property (possibly before type conversion)
|
||||
*/
|
||||
public PropertyValue(String name, Object value) {
|
||||
public PropertyValue(String name, @Nullable Object value) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
@@ -116,6 +118,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
* It is the responsibility of the BeanWrapper implementation to
|
||||
* perform type conversion.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ public interface PropertyValues {
|
||||
/**
|
||||
* Return the property value with the given name, if any.
|
||||
* @param propertyName the name to search for
|
||||
* @return the property value, or {@code null}
|
||||
* @return the property value, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
PropertyValue getPropertyValue(String propertyName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,7 +50,8 @@ public interface TypeConverter {
|
||||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
||||
|
||||
/**
|
||||
* Convert the value to the required type (if necessary from a String).
|
||||
@@ -68,8 +69,9 @@ public interface TypeConverter {
|
||||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws TypeMismatchException;
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam) throws TypeMismatchException;
|
||||
|
||||
/**
|
||||
* Convert the value to the required type (if necessary from a String).
|
||||
@@ -87,7 +89,8 @@ public interface TypeConverter {
|
||||
* @see org.springframework.core.convert.ConversionService
|
||||
* @see org.springframework.core.convert.converter.Converter
|
||||
*/
|
||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
@Nullable
|
||||
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws TypeMismatchException;
|
||||
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class TypeConverterDelegate {
|
||||
* @param propertyEditorRegistry the editor registry to use
|
||||
* @param targetObject the target object to work on (as context that can be passed to editors)
|
||||
*/
|
||||
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject) {
|
||||
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, @Nullable Object targetObject) {
|
||||
this.propertyEditorRegistry = propertyEditorRegistry;
|
||||
this.targetObject = targetObject;
|
||||
}
|
||||
@@ -91,8 +91,9 @@ class TypeConverterDelegate {
|
||||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam) throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(null, null, newValue, requiredType,
|
||||
(methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
|
||||
@@ -108,7 +109,8 @@ class TypeConverterDelegate {
|
||||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(null, null, newValue, requiredType,
|
||||
@@ -125,9 +127,9 @@ class TypeConverterDelegate {
|
||||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
public <T> T convertIfNecessary(
|
||||
String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class<T> requiredType)
|
||||
throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||
Object newValue, @Nullable Class<T> requiredType) throws IllegalArgumentException {
|
||||
|
||||
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
|
||||
}
|
||||
@@ -145,8 +147,9 @@ class TypeConverterDelegate {
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue,
|
||||
@Nullable Class<T> requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
||||
@Nullable
|
||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
|
||||
@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
||||
|
||||
// Custom editor for this type?
|
||||
PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);
|
||||
@@ -268,7 +271,7 @@ class TypeConverterDelegate {
|
||||
// Original exception from former ConversionService call above...
|
||||
throw conversionAttemptEx;
|
||||
}
|
||||
else if (conversionService != null) {
|
||||
else if (conversionService != null && typeDescriptor != null) {
|
||||
// ConversionService not tried before, probably custom editor found
|
||||
// but editor couldn't produce the required type...
|
||||
TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
|
||||
@@ -359,7 +362,7 @@ class TypeConverterDelegate {
|
||||
* @return the corresponding editor, or {@code null} if none
|
||||
*/
|
||||
@Nullable
|
||||
private PropertyEditor findDefaultEditor(Class<?> requiredType) {
|
||||
private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {
|
||||
PropertyEditor editor = null;
|
||||
if (requiredType != null) {
|
||||
// No custom editor -> check BeanWrapperImpl's default editors.
|
||||
@@ -383,7 +386,10 @@ class TypeConverterDelegate {
|
||||
* @return the new value, possibly the result of type conversion
|
||||
* @throws IllegalArgumentException if type conversion failed
|
||||
*/
|
||||
private Object doConvertValue(@Nullable Object oldValue, Object newValue, @Nullable Class<?> requiredType, PropertyEditor editor) {
|
||||
@Nullable
|
||||
private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
|
||||
@Nullable Class<?> requiredType, @Nullable PropertyEditor editor) {
|
||||
|
||||
Object convertedValue = newValue;
|
||||
|
||||
if (editor != null && !(convertedValue instanceof String)) {
|
||||
@@ -459,7 +465,7 @@ class TypeConverterDelegate {
|
||||
return editor.getValue();
|
||||
}
|
||||
|
||||
private Object convertToTypedArray(Object input, String propertyName, Class<?> componentType) {
|
||||
private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {
|
||||
if (input instanceof Collection) {
|
||||
// Convert Collection elements to array elements.
|
||||
Collection<?> coll = (Collection<?>) input;
|
||||
@@ -498,8 +504,8 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<?> convertToTypedCollection(
|
||||
Collection<?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Collection<?> convertToTypedCollection(Collection<?> original, @Nullable String propertyName,
|
||||
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Collection.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
@@ -515,7 +521,7 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
boolean originalAllowed = requiredType.isInstance(original);
|
||||
TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
|
||||
TypeDescriptor elementType = (typeDescriptor != null ? typeDescriptor.getElementTypeDescriptor() : null);
|
||||
if (elementType == null && originalAllowed &&
|
||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||
return original;
|
||||
@@ -524,13 +530,6 @@ class TypeConverterDelegate {
|
||||
Iterator<?> it;
|
||||
try {
|
||||
it = original.iterator();
|
||||
if (it == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Collection of type [" + original.getClass().getName() +
|
||||
"] returned null Iterator - injecting original Collection as-is");
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -580,8 +579,8 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<?, ?> convertToTypedMap(
|
||||
Map<?, ?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Map<?, ?> convertToTypedMap(Map<?, ?> original, @Nullable String propertyName,
|
||||
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Map.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
@@ -597,8 +596,8 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
boolean originalAllowed = requiredType.isInstance(original);
|
||||
TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor();
|
||||
TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor();
|
||||
TypeDescriptor keyType = (typeDescriptor != null ? typeDescriptor.getMapKeyTypeDescriptor() : null);
|
||||
TypeDescriptor valueType = (typeDescriptor != null ? typeDescriptor.getMapValueTypeDescriptor() : null);
|
||||
if (keyType == null && valueType == null && originalAllowed &&
|
||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||
return original;
|
||||
@@ -607,13 +606,6 @@ class TypeConverterDelegate {
|
||||
Iterator<?> it;
|
||||
try {
|
||||
it = original.entrySet().iterator();
|
||||
if (it == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Map of type [" + original.getClass().getName() +
|
||||
"] returned null Iterator - injecting original Map as-is");
|
||||
}
|
||||
return original;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -665,13 +657,15 @@ class TypeConverterDelegate {
|
||||
return (originalAllowed ? original : convertedCopy);
|
||||
}
|
||||
|
||||
private String buildIndexedPropertyName(String propertyName, int index) {
|
||||
@Nullable
|
||||
private String buildIndexedPropertyName(@Nullable String propertyName, int index) {
|
||||
return (propertyName != null ?
|
||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||
null);
|
||||
}
|
||||
|
||||
private String buildKeyedPropertyName(String propertyName, Object key) {
|
||||
@Nullable
|
||||
private String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
|
||||
return (propertyName != null ?
|
||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||
null);
|
||||
|
||||
@@ -37,26 +37,28 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
||||
return doConvert(value, requiredType, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return doConvert(value, requiredType, methodParam, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||
throws TypeMismatchException {
|
||||
|
||||
return doConvert(value, requiredType, null, field);
|
||||
}
|
||||
|
||||
private <T> T doConvert(Object value, Class<T> requiredType, @Nullable MethodParameter methodParam, @Nullable Field field)
|
||||
throws TypeMismatchException {
|
||||
@Nullable
|
||||
private <T> T doConvert(@Nullable Object value,@Nullable Class<T> requiredType,
|
||||
@Nullable MethodParameter methodParam, @Nullable Field field) throws TypeMismatchException {
|
||||
|
||||
try {
|
||||
if (field != null) {
|
||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field);
|
||||
@@ -65,16 +67,10 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
|
||||
}
|
||||
}
|
||||
catch (ConverterNotFoundException ex) {
|
||||
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConversionException | IllegalArgumentException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ public class TypeMismatchException extends PropertyAccessException {
|
||||
* @param requiredType the required target type (or {@code null} if not known)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
|
||||
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType,
|
||||
@Nullable Throwable cause) {
|
||||
|
||||
super(propertyChangeEvent,
|
||||
"Failed to convert property value of type '" +
|
||||
ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,7 +45,7 @@ public abstract class AnnotationBeanUtils {
|
||||
* @param excludedProperties the names of excluded properties, if any
|
||||
* @see org.springframework.beans.BeanWrapper
|
||||
*/
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable String... excludedProperties) {
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, String... excludedProperties) {
|
||||
copyPropertiesToBean(ann, bean, null, excludedProperties);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,9 @@ public abstract class AnnotationBeanUtils {
|
||||
* @param excludedProperties the names of excluded properties, if any
|
||||
* @see org.springframework.beans.BeanWrapper
|
||||
*/
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, @Nullable String... excludedProperties) {
|
||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver,
|
||||
String... excludedProperties) {
|
||||
|
||||
Set<String> excluded = new HashSet<>(Arrays.asList(excludedProperties));
|
||||
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
|
||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Callback that allows a bean to be aware of the bean
|
||||
* {@link ClassLoader class loader}; that is, the class loader used by the
|
||||
@@ -47,11 +45,8 @@ public interface BeanClassLoaderAware extends Aware {
|
||||
* {@link InitializingBean InitializingBean's}
|
||||
* {@link InitializingBean#afterPropertiesSet()}
|
||||
* method or a custom init-method.
|
||||
* @param classLoader the owning class loader; may be {@code null} in
|
||||
* which case a default {@code ClassLoader} must be used, for example
|
||||
* the {@code ClassLoader} obtained via
|
||||
* {@link org.springframework.util.ClassUtils#getDefaultClassLoader()}
|
||||
* @param classLoader the owning class loader
|
||||
*/
|
||||
void setBeanClassLoader(@Nullable ClassLoader classLoader);
|
||||
void setBeanClassLoader(ClassLoader classLoader);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,7 +64,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||
* @param msg the detail message
|
||||
*/
|
||||
public BeanCreationException(String beanName, String msg) {
|
||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") + ": " + msg);
|
||||
super("Error creating bean with name '" + beanName + "': " + msg);
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ public class BeanCreationException extends FatalBeanException {
|
||||
* @param beanName the name of the bean requested
|
||||
* @param msg the detail message
|
||||
*/
|
||||
public BeanCreationException(String resourceDescription, String beanName, String msg) {
|
||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") +
|
||||
public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, String msg) {
|
||||
super("Error creating bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
@@ -101,20 +101,12 @@ public class BeanCreationException extends FatalBeanException {
|
||||
* @param msg the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public BeanCreationException(String resourceDescription, String beanName, String msg, Throwable cause) {
|
||||
public BeanCreationException(@Nullable String resourceDescription, String beanName, String msg, Throwable cause) {
|
||||
this(resourceDescription, beanName, msg);
|
||||
initCause(cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the bean requested, if any.
|
||||
*/
|
||||
@Nullable
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the description of the resource that the bean
|
||||
* definition came from, if any.
|
||||
@@ -124,6 +116,13 @@ public class BeanCreationException extends FatalBeanException {
|
||||
return this.resourceDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the bean requested, if any.
|
||||
*/
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a related cause to this bean creation exception,
|
||||
* not being a direct cause of the failure but having occurred
|
||||
@@ -189,7 +188,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Class<?> exClass) {
|
||||
public boolean contains(@Nullable Class<?> exClass) {
|
||||
if (super.contains(exClass)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,7 +57,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
* @param resourceDescription description of the resource that the bean definition came from
|
||||
* @param msg the detail message (used as exception message as-is)
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String msg) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) {
|
||||
super(msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
* @param msg the detail message (used as exception message as-is)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
* @param msg the detail message (appended to an introductory message that indicates
|
||||
* the resource and the name of the bean)
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg) {
|
||||
this(resourceDescription, beanName, msg, null);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
* the resource and the name of the bean)
|
||||
* @param cause the root cause (may be {@code null})
|
||||
*/
|
||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -159,6 +159,22 @@ public interface BeanFactory {
|
||||
*/
|
||||
<T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
* overriding the specified default arguments (if any) in the bean definition.
|
||||
* @param name the name of the bean to retrieve
|
||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||
* the affected bean isn't a prototype
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @since 2.5
|
||||
*/
|
||||
Object getBean(String name, Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return the bean instance that uniquely matches the given object type, if any.
|
||||
* <p>This method goes into {@link ListableBeanFactory} by-type lookup territory
|
||||
@@ -176,22 +192,6 @@ public interface BeanFactory {
|
||||
*/
|
||||
<T> T getBean(Class<T> requiredType) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
* overriding the specified default arguments (if any) in the bean definition.
|
||||
* @param name the name of the bean to retrieve
|
||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||
* the affected bean isn't a prototype
|
||||
* @throws BeansException if the bean could not be created
|
||||
* @since 2.5
|
||||
*/
|
||||
Object getBean(String name, Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
* Return an instance, which may be shared or independent, of the specified bean.
|
||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||
@@ -298,7 +298,7 @@ public interface BeanFactory {
|
||||
* @see #getBean
|
||||
* @see #getType
|
||||
*/
|
||||
boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
||||
boolean isTypeMatch(String name, @Nullable Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
||||
|
||||
/**
|
||||
* Determine the type of the bean with the given name. More specifically,
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -57,7 +58,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @return whether the given name is a factory dereference
|
||||
* @see BeanFactory#FACTORY_BEAN_PREFIX
|
||||
*/
|
||||
public static boolean isFactoryDereference(String name) {
|
||||
public static boolean isFactoryDereference(@Nullable String name) {
|
||||
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionReaderUtils#generateBeanName
|
||||
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
||||
*/
|
||||
public static boolean isGeneratedBeanName(String name) {
|
||||
public static boolean isGeneratedBeanName(@Nullable String name) {
|
||||
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when the BeanFactory cannot load the specified class
|
||||
@@ -44,10 +45,10 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) {
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
|
||||
|
||||
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName +
|
||||
"' defined in " + resourceDescription, cause);
|
||||
super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
this.beanClassName = beanClassName;
|
||||
@@ -62,10 +63,11 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public CannotLoadBeanClassException(
|
||||
String resourceDescription, String beanName, String beanClassName, LinkageError cause) {
|
||||
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
|
||||
|
||||
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName +
|
||||
"' defined in " + resourceDescription + ": problem with class file or dependent class", cause);
|
||||
super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") +
|
||||
": problem with class file or dependent class", cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
this.beanClassName = beanClassName;
|
||||
|
||||
@@ -106,7 +106,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
|
||||
* <p>Bean names returned by this method should always return bean names <i>in the
|
||||
* order of definition</i> in the backend configuration, as far as possible.
|
||||
* @param type the class or interface to match, or {@code null} for all bean names
|
||||
* @param type the generically typed class or interface to match
|
||||
* @return the names of beans (or objects created by FactoryBeans) matching
|
||||
* the given object type (including subclasses), or an empty array if none
|
||||
* @since 4.2
|
||||
@@ -114,7 +114,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* @see FactoryBean#getObjectType
|
||||
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
|
||||
*/
|
||||
String[] getBeanNamesForType(@Nullable ResolvableType type);
|
||||
String[] getBeanNamesForType(ResolvableType type);
|
||||
|
||||
/**
|
||||
* Return the names of beans matching the given type (including subclasses),
|
||||
@@ -268,7 +268,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* found on the given class itself.
|
||||
* @param beanName the name of the bean to look for annotations on
|
||||
* @param annotationType the annotation class to look for
|
||||
* @return the annotation of the given type if found, or {@code null}
|
||||
* @return the annotation of the given type if found, or {@code null} otherwise
|
||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Defines a factory which can return an Object instance
|
||||
@@ -41,9 +42,10 @@ public interface ObjectFactory<T> {
|
||||
/**
|
||||
* Return an instance (possibly shared or independent)
|
||||
* of the object managed by this factory.
|
||||
* @return an instance of the bean (should never be {@code null})
|
||||
* @return the resulting instance
|
||||
* @throws BeansException in case of creation errors
|
||||
*/
|
||||
@Nullable
|
||||
T getObject() throws BeansException;
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public interface ObjectProvider<T> extends ObjectFactory<T> {
|
||||
* @throws BeansException in case of creation errors
|
||||
* @see #getObject()
|
||||
*/
|
||||
@Nullable
|
||||
T getObject(Object... args) throws BeansException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -228,10 +228,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||
if (beanType != null) {
|
||||
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -389,7 +387,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
|
||||
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
|
||||
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
|
||||
// Fall back to class name as cache key, for backwards compatibility with custom callers.
|
||||
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
|
||||
// Quick check on the concurrent map first, with minimal locking.
|
||||
@@ -512,7 +510,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
/**
|
||||
* Register the specified bean as dependent on the autowired beans.
|
||||
*/
|
||||
private void registerDependentBeans(String beanName, Set<String> autowiredBeanNames) {
|
||||
private void registerDependentBeans(@Nullable String beanName, Set<String> autowiredBeanNames) {
|
||||
if (beanName != null) {
|
||||
for (String autowiredBeanName : autowiredBeanNames) {
|
||||
if (this.beanFactory.containsBean(autowiredBeanName)) {
|
||||
@@ -529,7 +527,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
/**
|
||||
* Resolve the specified cached method argument or field value.
|
||||
*/
|
||||
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
|
||||
@Nullable
|
||||
private Object resolvedCachedArgument(@Nullable String beanName, Object cachedArgument) {
|
||||
if (cachedArgument instanceof DependencyDescriptor) {
|
||||
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
||||
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
|
||||
@@ -557,7 +556,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
Field field = (Field) this.member;
|
||||
Object value;
|
||||
if (this.cached) {
|
||||
@@ -615,13 +614,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
|
||||
private volatile Object[] cachedMethodArguments;
|
||||
|
||||
public AutowiredMethodElement(Method method, boolean required, PropertyDescriptor pd) {
|
||||
public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
|
||||
super(method, pd);
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
if (checkPropertySkipping(pvs)) {
|
||||
return;
|
||||
}
|
||||
@@ -694,7 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object[] resolveCachedArguments(String beanName) {
|
||||
private Object[] resolveCachedArguments(@Nullable String beanName) {
|
||||
if (this.cachedMethodArguments == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -120,7 +121,9 @@ public abstract class BeanFactoryAnnotationUtils {
|
||||
* qualifier value (through {@code <qualifier>} or {@code @Qualifier})
|
||||
* @since 5.0
|
||||
*/
|
||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName, BeanFactory beanFactory) {
|
||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName,
|
||||
@Nullable BeanFactory beanFactory) {
|
||||
|
||||
// Try quick bean name or alias match first...
|
||||
if (qualifier.test(beanName)) {
|
||||
return true;
|
||||
|
||||
@@ -121,10 +121,8 @@ public class InitDestroyAnnotationBeanPostProcessor
|
||||
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||
if (beanType != null) {
|
||||
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
||||
metadata.checkConfigMembers(beanDefinition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,7 +77,7 @@ public class InjectionMetadata {
|
||||
this.checkedElements = checkedElements;
|
||||
}
|
||||
|
||||
public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable {
|
||||
public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||
Collection<InjectedElement> elementsToIterate =
|
||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||
if (!elementsToIterate.isEmpty()) {
|
||||
@@ -94,7 +94,7 @@ public class InjectionMetadata {
|
||||
/**
|
||||
* @since 3.2.13
|
||||
*/
|
||||
public void clear(PropertyValues pvs) {
|
||||
public void clear(@Nullable PropertyValues pvs) {
|
||||
Collection<InjectedElement> elementsToIterate =
|
||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||
if (!elementsToIterate.isEmpty()) {
|
||||
@@ -105,7 +105,7 @@ public class InjectionMetadata {
|
||||
}
|
||||
|
||||
|
||||
public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz) {
|
||||
public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class<?> clazz) {
|
||||
return (metadata == null || metadata.targetClass != clazz);
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public class InjectionMetadata {
|
||||
|
||||
protected volatile Boolean skip;
|
||||
|
||||
protected InjectedElement(Member member, PropertyDescriptor pd) {
|
||||
protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
|
||||
this.member = member;
|
||||
this.isField = (member instanceof Field);
|
||||
this.pd = pd;
|
||||
@@ -163,7 +163,9 @@ public class InjectionMetadata {
|
||||
/**
|
||||
* Either this or {@link #getResourceToInject} needs to be overridden.
|
||||
*/
|
||||
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
|
||||
protected void inject(Object target, @Nullable String requestingBeanName, @Nullable PropertyValues pvs)
|
||||
throws Throwable {
|
||||
|
||||
if (this.isField) {
|
||||
Field field = (Field) this.member;
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
@@ -189,7 +191,7 @@ public class InjectionMetadata {
|
||||
* an explicit property value having been specified. Also marks the
|
||||
* affected property as processed for other processors to ignore it.
|
||||
*/
|
||||
protected boolean checkPropertySkipping(PropertyValues pvs) {
|
||||
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
|
||||
if (this.skip != null) {
|
||||
return this.skip;
|
||||
}
|
||||
@@ -219,7 +221,7 @@ public class InjectionMetadata {
|
||||
/**
|
||||
* @since 3.2.13
|
||||
*/
|
||||
protected void clearPropertySkipping(PropertyValues pvs) {
|
||||
protected void clearPropertySkipping(@Nullable PropertyValues pvs) {
|
||||
if (pvs == null) {
|
||||
return;
|
||||
}
|
||||
@@ -234,7 +236,7 @@ public class InjectionMetadata {
|
||||
* Either this or {@link #inject} needs to be overridden.
|
||||
*/
|
||||
@Nullable
|
||||
protected Object getResourceToInject(Object target, String requestingBeanName) {
|
||||
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||
@Override
|
||||
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
|
||||
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
|
||||
if (match && descriptor != null) {
|
||||
if (match) {
|
||||
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
|
||||
if (match) {
|
||||
MethodParameter methodParam = descriptor.getMethodParameter();
|
||||
@@ -298,11 +298,13 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
|
||||
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
|
||||
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.core.Conventions;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -170,7 +171,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
|
||||
* @param beanName the name of the bean to check against
|
||||
* @return {@code true} to skip the bean; {@code false} to process it
|
||||
*/
|
||||
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
protected boolean shouldSkip(@Nullable ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public abstract class AbstractFactoryBean<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -268,6 +268,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||
* @return the bean instance to use, either the original or a wrapped one
|
||||
* @throws BeansException if the initialization failed
|
||||
*/
|
||||
@Nullable
|
||||
Object initializeBean(Object existingBean, String beanName) throws BeansException;
|
||||
|
||||
/**
|
||||
@@ -280,6 +281,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||
* @throws BeansException if any post-processing failed
|
||||
* @see BeanPostProcessor#postProcessBeforeInitialization
|
||||
*/
|
||||
@Nullable
|
||||
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
|
||||
throws BeansException;
|
||||
|
||||
@@ -293,6 +295,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||
* @throws BeansException if any post-processing failed
|
||||
* @see BeanPostProcessor#postProcessAfterInitialization
|
||||
*/
|
||||
@Nullable
|
||||
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
|
||||
throws BeansException;
|
||||
|
||||
@@ -356,7 +359,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||
* @see DependencyDescriptor
|
||||
*/
|
||||
@Nullable
|
||||
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
|
||||
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
|
||||
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -101,7 +101,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
* @see #setFactoryBeanName
|
||||
* @see #setFactoryMethodName
|
||||
*/
|
||||
void setBeanClassName(String beanClassName);
|
||||
void setBeanClassName(@Nullable String beanClassName);
|
||||
|
||||
/**
|
||||
* Return the current bean class name of this bean definition.
|
||||
@@ -115,6 +115,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
* @see #getFactoryBeanName()
|
||||
* @see #getFactoryMethodName()
|
||||
*/
|
||||
@Nullable
|
||||
String getBeanClassName();
|
||||
|
||||
/**
|
||||
@@ -122,11 +123,10 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
* @see #SCOPE_SINGLETON
|
||||
* @see #SCOPE_PROTOTYPE
|
||||
*/
|
||||
void setScope(String scope);
|
||||
void setScope(@Nullable String scope);
|
||||
|
||||
/**
|
||||
* Return the name of the current target scope for this bean,
|
||||
* or {@code null} if not known yet.
|
||||
* Return the name of the current target scope for this bean.
|
||||
*/
|
||||
@Nullable
|
||||
String getScope();
|
||||
@@ -153,6 +153,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
/**
|
||||
* Return the bean names that this bean depends on.
|
||||
*/
|
||||
@Nullable
|
||||
String[] getDependsOn();
|
||||
|
||||
/**
|
||||
@@ -186,7 +187,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
* This the name of the bean to call the specified factory method on.
|
||||
* @see #setFactoryMethodName
|
||||
*/
|
||||
void setFactoryBeanName(String factoryBeanName);
|
||||
void setFactoryBeanName(@Nullable String factoryBeanName);
|
||||
|
||||
/**
|
||||
* Return the factory bean name, if any.
|
||||
@@ -202,7 +203,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
* @see #setFactoryBeanName
|
||||
* @see #setBeanClassName
|
||||
*/
|
||||
void setFactoryMethodName(String factoryMethodName);
|
||||
void setFactoryMethodName(@Nullable String factoryMethodName);
|
||||
|
||||
/**
|
||||
* Return a factory method, if any.
|
||||
@@ -259,6 +260,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||
/**
|
||||
* Return a human-readable description of this bean definition.
|
||||
*/
|
||||
@Nullable
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -120,7 +120,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
|
||||
* Determine whether the given candidate name matches the bean name
|
||||
* or the aliases stored in this bean definition.
|
||||
*/
|
||||
public boolean matchesName(String candidateName) {
|
||||
public boolean matchesName(@Nullable String candidateName) {
|
||||
return (candidateName != null && (candidateName.equals(this.beanName) ||
|
||||
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
|
||||
ObjectUtils.containsElement(this.aliases, candidateName)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
@@ -164,7 +165,8 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected Object resolveValue(Object value) {
|
||||
@Nullable
|
||||
protected Object resolveValue(@Nullable Object value) {
|
||||
if (value instanceof BeanDefinition) {
|
||||
visitBeanDefinition((BeanDefinition) value);
|
||||
}
|
||||
@@ -174,6 +176,9 @@ public class BeanDefinitionVisitor {
|
||||
else if (value instanceof RuntimeBeanReference) {
|
||||
RuntimeBeanReference ref = (RuntimeBeanReference) value;
|
||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||
if (newBeanName == null) {
|
||||
return null;
|
||||
}
|
||||
if (!newBeanName.equals(ref.getBeanName())) {
|
||||
return new RuntimeBeanReference(newBeanName);
|
||||
}
|
||||
@@ -181,6 +186,9 @@ public class BeanDefinitionVisitor {
|
||||
else if (value instanceof RuntimeBeanNameReference) {
|
||||
RuntimeBeanNameReference ref = (RuntimeBeanNameReference) value;
|
||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||
if (newBeanName == null) {
|
||||
return null;
|
||||
}
|
||||
if (!newBeanName.equals(ref.getBeanName())) {
|
||||
return new RuntimeBeanNameReference(newBeanName);
|
||||
}
|
||||
@@ -274,6 +282,7 @@ public class BeanDefinitionVisitor {
|
||||
* @param strVal the original String value
|
||||
* @return the resolved String value
|
||||
*/
|
||||
@Nullable
|
||||
protected String resolveStringValue(String strVal) {
|
||||
if (this.valueResolver == null) {
|
||||
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Strategy interface for resolving a value through evaluating it
|
||||
@@ -40,6 +41,7 @@ public interface BeanExpressionResolver {
|
||||
* @return the resolved value (potentially the given value as-is)
|
||||
* @throws BeansException if evaluation failed
|
||||
*/
|
||||
Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException;
|
||||
@Nullable
|
||||
Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -134,12 +134,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||
* here, supporting "#{...}" expressions in a Unified EL compatible style.
|
||||
* @since 3.0
|
||||
*/
|
||||
void setBeanExpressionResolver(BeanExpressionResolver resolver);
|
||||
void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver);
|
||||
|
||||
/**
|
||||
* Return the resolution strategy for expressions in bean definition values.
|
||||
* @since 3.0
|
||||
*/
|
||||
@Nullable
|
||||
BeanExpressionResolver getBeanExpressionResolver();
|
||||
|
||||
/**
|
||||
@@ -147,7 +148,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||
* @since 3.0
|
||||
*/
|
||||
void setConversionService(ConversionService conversionService);
|
||||
void setConversionService(@Nullable ConversionService conversionService);
|
||||
|
||||
/**
|
||||
* Return the associated ConversionService, if any.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,7 +78,7 @@ public interface ConfigurableListableBeanFactory
|
||||
* implementation of the {@link org.springframework.beans.factory.ObjectFactory}
|
||||
* interface, which allows for lazy resolution of the actual target value.
|
||||
*/
|
||||
void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);
|
||||
void registerResolvableDependency(Class<?> dependencyType, @Nullable Object autowiredValue);
|
||||
|
||||
/**
|
||||
* Determine whether the specified bean qualifies as an autowire candidate,
|
||||
@@ -106,7 +106,7 @@ public interface ConfigurableListableBeanFactory
|
||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* defined in this factory
|
||||
*/
|
||||
BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException;
|
||||
BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
|
||||
|
||||
/**
|
||||
* Return a unified view over all bean names managed by this factory.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ public class ConstructorArgumentValues {
|
||||
* to allow for merging and re-merging of argument value definitions. Distinct
|
||||
* ValueHolder instances carrying the same content are of course allowed.
|
||||
*/
|
||||
public void addArgumentValues(ConstructorArgumentValues other) {
|
||||
public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
|
||||
if (other != null) {
|
||||
for (Map.Entry<Integer, ValueHolder> entry : other.indexedArgumentValues.entrySet()) {
|
||||
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
|
||||
@@ -89,7 +89,7 @@ public class ConstructorArgumentValues {
|
||||
* @param index the index in the constructor argument list
|
||||
* @param value the argument value
|
||||
*/
|
||||
public void addIndexedArgumentValue(int index, Object value) {
|
||||
public void addIndexedArgumentValue(int index, @Nullable Object value) {
|
||||
addIndexedArgumentValue(index, new ValueHolder(value));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ConstructorArgumentValues {
|
||||
* @param value the argument value
|
||||
* @param type the type of the constructor argument
|
||||
*/
|
||||
public void addIndexedArgumentValue(int index, Object value, String type) {
|
||||
public void addIndexedArgumentValue(int index, @Nullable Object value, String type) {
|
||||
addIndexedArgumentValue(index, new ValueHolder(value, type));
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ public class ConstructorArgumentValues {
|
||||
* Create a new ValueHolder for the given value.
|
||||
* @param value the argument value
|
||||
*/
|
||||
public ValueHolder(Object value) {
|
||||
public ValueHolder(@Nullable Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ public class ConstructorArgumentValues {
|
||||
* @param value the argument value
|
||||
* @param type the type of the constructor argument
|
||||
*/
|
||||
public ValueHolder(Object value, String type) {
|
||||
public ValueHolder(@Nullable Object value, @Nullable String type) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ public class ConstructorArgumentValues {
|
||||
* @param type the type of the constructor argument
|
||||
* @param name the name of the constructor argument
|
||||
*/
|
||||
public ValueHolder(Object value, String type, String name) {
|
||||
public ValueHolder(@Nullable Object value, @Nullable String type, @Nullable String name) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
@@ -483,13 +483,14 @@ public class ConstructorArgumentValues {
|
||||
* Set the value for the constructor argument.
|
||||
* @see PropertyPlaceholderConfigurer
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
public void setValue(@Nullable Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value for the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
@@ -497,13 +498,14 @@ public class ConstructorArgumentValues {
|
||||
/**
|
||||
* Set the type of the constructor argument.
|
||||
*/
|
||||
public void setType(String type) {
|
||||
public void setType(@Nullable String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
@@ -511,13 +513,14 @@ public class ConstructorArgumentValues {
|
||||
/**
|
||||
* Set the name of the constructor argument.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
public void setName(@Nullable String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the constructor argument.
|
||||
*/
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -526,11 +529,12 @@ public class ConstructorArgumentValues {
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
@@ -99,12 +99,9 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||
|
||||
this.declaringClass = methodParameter.getDeclaringClass();
|
||||
if (this.methodParameter.getMethod() != null) {
|
||||
this.methodName = methodParameter.getMethod().getName();
|
||||
this.parameterTypes = methodParameter.getMethod().getParameterTypes();
|
||||
}
|
||||
else {
|
||||
this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
|
||||
this.methodName = this.methodParameter.getMethod().getName();
|
||||
}
|
||||
this.parameterTypes = methodParameter.getExecutable().getParameterTypes();
|
||||
this.parameterIndex = methodParameter.getParameterIndex();
|
||||
this.containingClass = methodParameter.getContainingClass();
|
||||
this.required = required;
|
||||
@@ -334,6 +331,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||
* Determine the name of the wrapped parameter/field.
|
||||
* @return the declared name (never {@code null})
|
||||
*/
|
||||
@Nullable
|
||||
public String getDependencyName() {
|
||||
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,6 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
||||
* <p>This can be specified to not log into the category of this warner class but rather
|
||||
* into a specific named category.
|
||||
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
||||
* @see org.apache.log4j.Logger#getLogger(String)
|
||||
* @see java.util.logging.Logger#getLogger(String)
|
||||
*/
|
||||
public void setLoggerName(String loggerName) {
|
||||
@@ -61,10 +60,13 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
||||
if (beanFactory.isFactoryBean(beanName)) {
|
||||
nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
|
||||
}
|
||||
Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
|
||||
if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||
logDeprecatedBean(beanName, beanType, beanDefinition);
|
||||
Class<?> beanType = beanFactory.getType(nameToLookup);
|
||||
if (beanType != null) {
|
||||
Class<?> userClass = ClassUtils.getUserClass(beanType);
|
||||
if (userClass.isAnnotationPresent(Deprecated.class)) {
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||
logDeprecatedBean(beanName, beanType, beanDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -149,7 +149,7 @@ public class FieldRetrievingFactoryBean
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<List<Object>> {
|
||||
* @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");
|
||||
}
|
||||
|
||||
@@ -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<Map<Object, Object>> {
|
||||
* @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");
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<T> 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<T> 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<T> implements NamedBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the corresponding bean instance (can be {@code null}).
|
||||
* Return the corresponding bean instance.
|
||||
*/
|
||||
@Nullable
|
||||
public T getBeanInstance() {
|
||||
return this.beanInstance;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-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.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-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<Object>, 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<Object>, 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();
|
||||
|
||||
@@ -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<Set<Object>> {
|
||||
* @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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
* <p>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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
return getInstantiationStrategy().instantiate(bd, null, parent);
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
bean = AccessController.doPrivileged((PrivilegedAction<Object>) () ->
|
||||
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<Object>() {
|
||||
@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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
return getInstantiationStrategy().instantiate(mbd, beanName, parent);
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
beanInstance = AccessController.doPrivileged((PrivilegedAction<Object>) () ->
|
||||
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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
invokeAwareMethods(beanName, bean);
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
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<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
((InitializingBean) bean).afterPropertiesSet();
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
|
||||
((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<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
ReflectionUtils.makeAccessible(initMethod);
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(initMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
initMethod.invoke(bean);
|
||||
return null;
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
initMethod.invoke(bean), getAccessControlContext());
|
||||
}
|
||||
catch (PrivilegedActionException pae) {
|
||||
InvocationTargetException ex = (InvocationTargetException) pae.getException();
|
||||
|
||||
@@ -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}.
|
||||
* <p>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.
|
||||
* <p>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}.
|
||||
* <p>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.
|
||||
* <p>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}.
|
||||
* <p>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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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).
|
||||
* <p>Default is a {@link DefaultBeanNameGenerator}.
|
||||
*/
|
||||
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
|
||||
public void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) {
|
||||
this.beanNameGenerator = (beanNameGenerator != null ? beanNameGenerator : new DefaultBeanNameGenerator());
|
||||
}
|
||||
|
||||
|
||||
@@ -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> T getBean(String name, Class<T> requiredType, Object... args) throws BeansException {
|
||||
public <T> T getBean(String name, @Nullable Class<T> 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> T doGetBean(
|
||||
final String name, @Nullable final Class<T> requiredType, @Nullable final Object[] args, boolean typeCheckOnly)
|
||||
throws BeansException {
|
||||
protected <T> T doGetBean(final String name, @Nullable final Class<T> 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<Object>() {
|
||||
@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<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
return ((fb instanceof SmartFactoryBean && ((SmartFactoryBean<?>) fb).isPrototype()) ||
|
||||
!fb.isSingleton());
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
return AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
|
||||
((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<Class<?>>() {
|
||||
@Override
|
||||
public Class<?> run() throws Exception {
|
||||
return doResolveBeanClass(mbd, typesToMatch);
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<Class<?>>) () ->
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -73,7 +73,9 @@ public class BeanDefinitionBuilder {
|
||||
* @param instanceSupplier a callback for creating an instance of the bean
|
||||
* @since 5.0
|
||||
*/
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(
|
||||
@Nullable Class<T> beanClass, Supplier<T> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 <b>ResourcePatternResolver</b> interface and cast
|
||||
* accordingly, for loading multiple resources for a given resource pattern.
|
||||
* <p>Null suggests that absolute resource loading is not available
|
||||
* for this bean definition reader.
|
||||
* <p>A {@code null} return value suggests that absolute resource loading
|
||||
* is not available for this bean definition reader.
|
||||
* <p>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();
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
return beanFactory.getInstantiationStrategy().instantiate(
|
||||
mbd, beanName, beanFactory, ctorToUse, argumentsToUse);
|
||||
}
|
||||
}, beanFactory.getAccessControlContext());
|
||||
beanInstance = AccessController.doPrivileged((PrivilegedAction<Object>) () ->
|
||||
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<Method[]>() {
|
||||
@Override
|
||||
public Method[] run() {
|
||||
return (mbd.isNonPublicAccessAllowed() ?
|
||||
ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
|
||||
}
|
||||
});
|
||||
return AccessController.doPrivileged((PrivilegedAction<Method[]>) () ->
|
||||
(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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
return beanFactory.getInstantiationStrategy().instantiate(
|
||||
mbd, beanName, beanFactory, fb, factoryMethod, args);
|
||||
}
|
||||
}, beanFactory.getAccessControlContext());
|
||||
beanInstance = AccessController.doPrivileged((PrivilegedAction<Object>) () ->
|
||||
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<ConstructorArgumentValues.ValueHolder> usedValueHolders =
|
||||
new HashSet<>(paramTypes.length);
|
||||
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = new HashSet<>(paramTypes.length);
|
||||
Set<String> 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<String> 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);
|
||||
|
||||
@@ -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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(DefaultListableBeanFactory.this);
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
((BeanFactoryAware) autowireCandidateResolver).setBeanFactory(DefaultListableBeanFactory.this);
|
||||
return null;
|
||||
}, getAccessControlContext());
|
||||
}
|
||||
else {
|
||||
@@ -334,14 +330,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
|
||||
public <T> T getBean(Class<T> requiredType, @Nullable Object... args) throws BeansException {
|
||||
NamedBeanHolder<T> 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<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
return ((SmartFactoryBean<?>) factory).isEagerInit();
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
isEagerInit = AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
|
||||
((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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
smartSingleton.afterSingletonsInstantiated();
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
smartSingleton.afterSingletonsInstantiated();
|
||||
return null;
|
||||
}, getAccessControlContext());
|
||||
}
|
||||
else {
|
||||
@@ -991,7 +981,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
private <T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType, Object... args) throws BeansException {
|
||||
private <T> NamedBeanHolder<T> resolveNamedBean(Class<T> 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<String> 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<String> 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<String> autowiredBeanNames, TypeConverter typeConverter) {
|
||||
private Object resolveMultipleBeans(DependencyDescriptor descriptor, @Nullable String beanName,
|
||||
@Nullable Set<String> 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<Object> adaptDependencyComparator(Map<String, Object> matchingBeans) {
|
||||
Comparator<Object> comparator = getDependencyComparator();
|
||||
if (comparator instanceof OrderComparator) {
|
||||
@@ -1254,7 +1245,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
* @see #autowireConstructor
|
||||
*/
|
||||
protected Map<String, Object> 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<Object> {
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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<String> dependencies = this.dependentBeanMap.remove(beanName);
|
||||
if (dependencies != null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,7 +95,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
* (potentially DestructionAwareBeanPostProcessor), if any
|
||||
*/
|
||||
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
|
||||
List<BeanPostProcessor> postProcessors, AccessControlContext acc) {
|
||||
List<BeanPostProcessor> 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<DestructionAwareBeanPostProcessor> postProcessors) {
|
||||
@Nullable List<DestructionAwareBeanPostProcessor> 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<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> processors, Object bean) {
|
||||
List<DestructionAwareBeanPostProcessor> 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<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
((DisposableBean) bean).destroy();
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
|
||||
((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<Method>() {
|
||||
@Override
|
||||
public Method run() {
|
||||
return findDestroyMethod();
|
||||
}
|
||||
});
|
||||
return AccessController.doPrivileged((PrivilegedAction<Method>) () -> 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<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
ReflectionUtils.makeAccessible(destroyMethod);
|
||||
return null;
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||
ReflectionUtils.makeAccessible(destroyMethod);
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
destroyMethod.invoke(bean, args);
|
||||
return null;
|
||||
}
|
||||
}, acc);
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Class<?>>() {
|
||||
@Override
|
||||
public Class<?> run() {
|
||||
return factoryBean.getObjectType();
|
||||
}
|
||||
}, getAccessControlContext());
|
||||
return AccessController.doPrivileged((PrivilegedAction<Class<?>>) () ->
|
||||
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<Object>() {
|
||||
@Override
|
||||
public Object run() throws Exception {
|
||||
return factory.getObject();
|
||||
}
|
||||
}, acc);
|
||||
object = AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<E> extends ArrayList<E> implements Mergeable, BeanMetad
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,7 +55,7 @@ public class ManagedMap<K, V> extends LinkedHashMap<K, V> implements Mergeable,
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-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.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,7 +53,7 @@ public class ManagedSet<E> extends LinkedHashSet<E> implements Mergeable, BeanMe
|
||||
* Set the configuration source {@code Object} for this metadata element.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-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.
|
||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||
*/
|
||||
public void setSource(Object source) {
|
||||
public void setSource(@Nullable Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user