Fix overridden methods nullability

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

View File

@@ -483,6 +483,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public Class<?> getPropertyType(String propertyName) throws BeansException {
try {
PropertyHandler ph = getPropertyHandler(propertyName);
@@ -510,6 +511,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
try {
AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);
@@ -603,6 +605,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public Object getPropertyValue(String propertyName) throws BeansException {
AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);
PropertyTokenHolder tokens = getPropertyNameTokens(getFinalPath(nestedPa, propertyName));

View File

@@ -127,6 +127,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
// Redefined with public visibility.
@Override
@Nullable
public Class<?> getPropertyType(String propertyPath) {
return null;
}
@@ -141,6 +142,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
* accessor method failed
*/
@Override
@Nullable
public abstract Object getPropertyValue(String propertyName) throws BeansException;
/**

View File

@@ -74,12 +74,14 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
}
@Override
@Nullable
public Object getAttribute(String name) {
BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.getAttribute(name);
return (attribute != null ? attribute.getValue() : null);
}
@Override
@Nullable
public Object removeAttribute(String name) {
BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.removeAttribute(name);
return (attribute != null ? attribute.getValue() : null);

View File

@@ -225,6 +225,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
@Nullable
protected BeanPropertyHandler getLocalPropertyHandler(String propertyName) {
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(propertyName);
if (pd != null) {
@@ -284,11 +285,13 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
@Nullable
public TypeDescriptor nested(int level) {
return TypeDescriptor.nested(property(pd), level);
}
@Override
@Nullable
public Object getValue() throws Exception {
final Method readMethod = this.pd.getReadMethod();
if (System.getSecurityManager() != null) {

View File

@@ -117,11 +117,13 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
}
@Override
@Nullable
public TypeDescriptor nested(int level) {
return TypeDescriptor.nested(this.field, level);
}
@Override
@Nullable
public Object getValue() throws Exception {
try {
ReflectionUtils.makeAccessible(this.field);

View File

@@ -22,6 +22,7 @@ import java.beans.Introspector;
import java.lang.reflect.Method;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
/**
* {@link BeanInfoFactory} implementation that evaluates whether bean classes have
@@ -42,6 +43,7 @@ public class ExtendedBeanInfoFactory implements BeanInfoFactory, Ordered {
* Return an {@link ExtendedBeanInfo} for the given bean class, if applicable.
*/
@Override
@Nullable
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
return (supports(beanClass) ? new ExtendedBeanInfo(Introspector.getBeanInfo(beanClass)) : null);
}

View File

@@ -250,6 +250,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
}
@Override
@Nullable
public PropertyValue getPropertyValue(String propertyName) {
for (PropertyValue pv : this.propertyValueList) {
if (pv.getName().equals(propertyName)) {

View File

@@ -39,11 +39,13 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
return doConvert(value, requiredType, null, null);
}
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
throws TypeMismatchException {
@@ -51,6 +53,7 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
}
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
throws TypeMismatchException {

View File

@@ -18,6 +18,7 @@ package org.springframework.beans.factory.annotation;
import org.springframework.beans.factory.wiring.BeanWiringInfo;
import org.springframework.beans.factory.wiring.BeanWiringInfoResolver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -37,6 +38,7 @@ import org.springframework.util.ClassUtils;
public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver {
@Override
@Nullable
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
Assert.notNull(beanInstance, "Bean instance must not be null");
Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);

View File

@@ -234,6 +234,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
@Override
@Nullable
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, final String beanName)
throws BeanCreationException {

View File

@@ -330,6 +330,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
* @see Value
*/
@Override
@Nullable
public Object getSuggestedValue(DependencyDescriptor descriptor) {
Object value = findValue(descriptor.getAnnotations());
if (value == null) {

View File

@@ -206,6 +206,7 @@ public abstract class AbstractFactoryBean<T>
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
@Nullable
public abstract Class<?> getObjectType();
/**

View File

@@ -113,6 +113,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
* @see BeanDefinition#getSource()
*/
@Override
@Nullable
public Object getSource() {
return this.beanDefinition.getSource();
}

View File

@@ -49,6 +49,7 @@ public class EmbeddedValueResolver implements StringValueResolver {
@Override
@Nullable
public String resolveStringValue(String strVal) {
String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal);
if (this.exprResolver != null && value != null) {

View File

@@ -208,6 +208,7 @@ public class FieldRetrievingFactoryBean
@Override
@Nullable
public Object getObject() throws IllegalAccessException {
if (this.fieldObject == null) {
throw new FactoryBeanNotInitializedException();

View File

@@ -21,6 +21,7 @@ import java.lang.reflect.Constructor;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.lang.Nullable;
/**
* Adapter that implements all methods on {@link SmartInstantiationAwareBeanPostProcessor}
@@ -40,11 +41,13 @@ import org.springframework.beans.PropertyValues;
public abstract class InstantiationAwareBeanPostProcessorAdapter implements SmartInstantiationAwareBeanPostProcessor {
@Override
@Nullable
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
return null;
}
@Override
@Nullable
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
return null;
}
@@ -55,6 +58,7 @@ public abstract class InstantiationAwareBeanPostProcessorAdapter implements Smar
}
@Override
@Nullable
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
return null;
}

View File

@@ -116,6 +116,7 @@ public class MethodInvokingFactoryBean extends MethodInvokingBean implements Fac
* specified method on the fly.
*/
@Override
@Nullable
public Object getObject() throws Exception {
if (this.singleton) {
if (!this.initialized) {

View File

@@ -75,6 +75,7 @@ public class PropertiesFactoryBean extends PropertiesLoaderSupport
}
@Override
@Nullable
public final Properties getObject() throws IOException {
if (this.singleton) {
return this.singletonInstance;

View File

@@ -201,6 +201,7 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
@Override
@Nullable
public Object getObject() throws BeansException {
BeanWrapper target = this.targetBeanWrapper;
if (target != null) {

View File

@@ -239,6 +239,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
}
@Override
@Nullable
public String resolveStringValue(String strVal) throws BeansException {
String resolved = this.helper.replacePlaceholders(strVal, this.resolver);
if (trimValues) {
@@ -258,6 +259,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
}
@Override
@Nullable
public String resolvePlaceholder(String placeholderName) {
return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, props, systemPropertiesMode);
}

View File

@@ -329,6 +329,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
@Override
@Nullable
public Object getObject() {
return this.proxy;
}

View File

@@ -97,6 +97,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
}
@Override
@Nullable
public Map<String, Object> getObject() {
return (this.map != null ? this.map : createMap());
}

View File

@@ -108,6 +108,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB
}
@Override
@Nullable
public Properties getObject() {
return (this.properties != null ? this.properties : createProperties());
}

View File

@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.ServiceLoader;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.lang.Nullable;
/**
* {@link org.springframework.beans.factory.FactoryBean} that exposes the
@@ -43,6 +44,7 @@ public class ServiceFactoryBean extends AbstractServiceLoaderBasedFactoryBean im
}
@Override
@Nullable
public Class<?> getObjectType() {
return getServiceType();
}

View File

@@ -340,6 +340,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
@Override
@Nullable
public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException {
return resolveDependency(descriptor, requestingBeanName, null, null);
}
@@ -409,11 +410,13 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
@Override
@Nullable
public Object initializeBean(Object existingBean, String beanName) {
return initializeBean(beanName, existingBean, null);
}
@Override
@Nullable
public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
throws BeansException {
@@ -428,6 +431,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
@Override
@Nullable
public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
throws BeansException {
@@ -457,6 +461,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #doCreateBean
*/
@Override
@Nullable
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
throws BeanCreationException {
@@ -634,6 +639,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
@Override
@Nullable
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch);
@@ -800,6 +806,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* it will be fully created to check the type of its exposed object.
*/
@Override
@Nullable
protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
String factoryBeanName = mbd.getFactoryBeanName();
String factoryMethodName = mbd.getFactoryMethodName();
@@ -1177,6 +1184,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #obtainFromSupplier
*/
@Override
@Nullable
protected Object getObjectForBeanInstance(
@Nullable Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) {

View File

@@ -358,6 +358,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* Return the current bean class name of this bean definition.
*/
@Override
@Nullable
public String getBeanClassName() {
Object beanClassObject = this.beanClass;
if (beanClassObject instanceof Class) {
@@ -971,6 +972,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* came from (for the purpose of showing context in case of errors).
*/
@Override
@Nullable
public String getResourceDescription() {
return (this.resource != null ? this.resource.getDescription() : null);
}
@@ -989,6 +991,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* originator chain to find the original BeanDefinition as defined by the user.
*/
@Override
@Nullable
public BeanDefinition getOriginatingBeanDefinition() {
return (this.resource instanceof BeanDefinitionResource ?
((BeanDefinitionResource) this.resource).getBeanDefinition() : null);

View File

@@ -599,6 +599,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public Class<?> getType(String name) throws NoSuchBeanDefinitionException {
String beanName = transformedBeanName(name);
@@ -840,6 +841,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public String resolveEmbeddedValue(@Nullable String value) {
if (value == null) {
return null;
@@ -926,6 +928,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
}
@Override
@Nullable
public Scope getRegisteredScope(String scopeName) {
Assert.notNull(scopeName, "Scope identifier must not be null");
return this.scopes.get(scopeName);

View File

@@ -570,6 +570,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
* if not found on the exposed bean reference (e.g. in case of a proxy).
*/
@Override
@Nullable
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException{
@@ -1037,6 +1038,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {
@@ -1613,6 +1615,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object getObject() throws BeansException {
if (this.optional) {
return createOptionalDependency(this.descriptor, this.beanName);
@@ -1623,6 +1626,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object getObject(final Object... args) throws BeansException {
if (this.optional) {
return createOptionalDependency(this.descriptor, this.beanName, args);
@@ -1639,6 +1643,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object getIfAvailable() throws BeansException {
if (this.optional) {
return createOptionalDependency(this.descriptor, this.beanName);
@@ -1655,6 +1660,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object getIfUnique() throws BeansException {
DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) {
@Override
@@ -1662,6 +1668,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return false;
}
@Override
@Nullable
public Object resolveNotUnique(Class<?> type, Map<String, Object> matchingBeans) {
return null;
}
@@ -1720,6 +1727,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
@Nullable
public Object getOrderSource(Object obj) {
RootBeanDefinition beanDefinition = getRootBeanDefinition(this.instancesToBeanNames.get(obj));
if (beanDefinition == null) {

View File

@@ -171,6 +171,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
}
@Override
@Nullable
public Object getSingleton(String beanName) {
return getSingleton(beanName, true);
}

View File

@@ -41,11 +41,13 @@ public class SimpleAutowireCandidateResolver implements AutowireCandidateResolve
}
@Override
@Nullable
public Object getSuggestedValue(DependencyDescriptor descriptor) {
return null;
}
@Override
@Nullable
public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) {
return null;
}

View File

@@ -355,6 +355,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
}
@Override
@Nullable
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException{

View File

@@ -58,6 +58,7 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
@Override
@Nullable
public final BeanDefinition parse(Element element, ParserContext parserContext) {
AbstractBeanDefinition definition = parseInternal(element, parserContext);
if (definition != null && !parserContext.isNested()) {

View File

@@ -113,6 +113,7 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver
* @return the located {@link NamespaceHandler}, or {@code null} if none found
*/
@Override
@Nullable
public NamespaceHandler resolve(String namespaceUri) {
Map<String, Object> handlerMappings = getHandlerMappings();
Object handlerOrClassName = handlerMappings.get(namespaceUri);

View File

@@ -68,6 +68,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
* registered for that {@link Element}.
*/
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
BeanDefinitionParser parser = findParserForElement(element, parserContext);
return (parser != null ? parser.parse(element, parserContext) : null);
@@ -93,6 +94,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler {
* is registered to handle that {@link Node}.
*/
@Override
@Nullable
public BeanDefinitionHolder decorate(
Node node, BeanDefinitionHolder definition, ParserContext parserContext) {

View File

@@ -71,6 +71,7 @@ public class ResourceEntityResolver extends DelegatingEntityResolver {
@Override
@Nullable
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws SAXException, IOException {
InputSource source = super.resolveEntity(publicId, systemId);
if (source == null && systemId != null) {

View File

@@ -28,6 +28,7 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.core.Conventions;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -68,6 +69,7 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
}
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
parserContext.getReaderContext().error(
"Class [" + getClass().getName() + "] does not support custom elements.", element);

View File

@@ -25,6 +25,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.core.Conventions;
import org.springframework.lang.Nullable;
/**
* Simple {@code NamespaceHandler} implementation that maps custom attributes
@@ -57,6 +58,7 @@ public class SimplePropertyNamespaceHandler implements NamespaceHandler {
}
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
parserContext.getReaderContext().error(
"Class [" + getClass().getName() + "] does not support custom elements.", element);