Skip to content

Commit

Permalink
Backport further refinements from the nullability efforts
Browse files Browse the repository at this point in the history
Issue: SPR-15656
  • Loading branch information
jhoeller committed Sep 27, 2017
1 parent 5f167fd commit cc70fdc
Show file tree
Hide file tree
Showing 50 changed files with 382 additions and 532 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -55,10 +55,10 @@
* 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
Expand Down Expand Up @@ -96,9 +96,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA

Object rootObject;

/**
* Map with cached nested Accessors: nested path -> Accessor instance.
*/
/** Map with cached nested Accessors: nested path -> Accessor instance */
private Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors;


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -46,8 +46,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
public CannotLoadBeanClassException(
String resourceDescription, String beanName, 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;
Expand All @@ -64,8 +64,9 @@ public CannotLoadBeanClassException(
public CannotLoadBeanClassException(
String resourceDescription, String beanName, 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,14 @@ public void setContainingClass(Class<?> containingClass) {
* @since 4.0
*/
public ResolvableType getResolvableType() {
if (this.resolvableType == null) {
this.resolvableType = (this.field != null ?
ResolvableType resolvableType = this.resolvableType;
if (resolvableType == null) {
resolvableType = (this.field != null ?
ResolvableType.forField(this.field, this.nestingLevel, this.containingClass) :
ResolvableType.forMethodParameter(this.methodParameter));
this.resolvableType = resolvableType;
}
return this.resolvableType;
return resolvableType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,6 +35,7 @@
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
Expand Down Expand Up @@ -134,12 +135,21 @@ public Object getBean(String name) throws BeansException {
@SuppressWarnings("unchecked")
public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
Object bean = getBean(name);
if (requiredType != null && !requiredType.isAssignableFrom(bean.getClass())) {
if (requiredType != null && !requiredType.isInstance(bean)) {
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
return (T) bean;
}

@Override
public Object getBean(String name, Object... args) throws BeansException {
if (!ObjectUtils.isEmpty(args)) {
throw new UnsupportedOperationException(
"StaticListableBeanFactory does not support explicit bean creation arguments");
}
return getBean(name);
}

@Override
public <T> T getBean(Class<T> requiredType) throws BeansException {
String[] beanNames = getBeanNamesForType(requiredType);
Expand All @@ -154,18 +164,9 @@ else if (beanNames.length > 1) {
}
}

@Override
public Object getBean(String name, Object... args) throws BeansException {
if (args != null) {
throw new UnsupportedOperationException(
"StaticListableBeanFactory does not support explicit bean creation arguments");
}
return getBean(name);
}

@Override
public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
if (args != null) {
if (!ObjectUtils.isEmpty(args)) {
throw new UnsupportedOperationException(
"StaticListableBeanFactory does not support explicit bean creation arguments");
}
Expand Down Expand Up @@ -352,7 +353,8 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException{

return AnnotationUtils.findAnnotation(getType(beanName), annotationType);
Class<?> beanType = getType(beanName);
return (beanType != null ? AnnotationUtils.findAnnotation(beanType, annotationType) : null);
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -140,7 +140,7 @@ protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefin
/**
* Central template method to actually parse the supplied {@link Element}
* into one or more {@link BeanDefinition BeanDefinitions}.
* @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
* @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
* @param parserContext the object encapsulating the current state of the parsing process;
* provides access to a {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
* @return the primary {@link BeanDefinition} resulting from the parsing of the supplied {@link Element}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ else if (parentDefaults != null) {
}

/**
* Return the defaults definition object, or {@code null} if the
* defaults have been initialized yet.
* Return the defaults definition object.
*/
public DocumentDefaultsDefinition getDefaults() {
return this.defaults;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,43 +25,39 @@
* Context information for use by {@link Condition}s.
*
* @author Phillip Webb
* @author Juergen Hoeller
* @since 4.0
*/
public interface ConditionContext {

/**
* Return the {@link BeanDefinitionRegistry} that will hold the bean definition
* should the condition match or {@code null} if the registry is not available.
* @return the registry or {@code null}
* should the condition match, or {@code null} if the registry is not available.
*/
BeanDefinitionRegistry getRegistry();

/**
* Return the {@link ConfigurableListableBeanFactory} that will hold the bean
* definition should the condition match or {@code null} if the bean factory
* definition should the condition match, or {@code null} if the bean factory
* is not available.
* @return the bean factory or {@code null}
*/
ConfigurableListableBeanFactory getBeanFactory();

/**
* Return the {@link Environment} for which the current application is running
* Return the {@link Environment} for which the current application is running,
* or {@code null} if no environment is available.
* @return the environment or {@code null}
*/
Environment getEnvironment();

/**
* Return the {@link ResourceLoader} currently being used or {@code null}
* if the resource loader cannot be obtained.
* @return a resource loader or {@code null}
* Return the {@link ResourceLoader} currently being used, or {@code null} if
* the resource loader cannot be obtained.
*/
ResourceLoader getResourceLoader();

/**
* Return the {@link ClassLoader} that should be used to load additional
* classes or {@code null} if the default classloader should be used.
* @return the class loader or {@code null}
* Return the {@link ClassLoader} that should be used to load additional classes,
* or {@code null} if the default classloader should be used.
*/
ClassLoader getClassLoader();

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,19 +22,19 @@
*/
public interface IJmxTestBean {

public int add(int x, int y);
int add(int x, int y);

public long myOperation();
long myOperation();

public int getAge();
int getAge();

public void setAge(int age);
void setAge(int age);

public void setName(String name) throws Exception;
void setName(String name) throws Exception;

public String getName();
String getName();

// used to test invalid methods that exist in the proxy interface
public void dontExposeMe();
void dontExposeMe();

}
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public static String classPackageAsResourcePath(Class<?> clazz) {
* in the given array.
* <p>Basically like {@code AbstractCollection.toString()}, but stripping
* the "class "/"interface " prefix before every class name.
* @param classes a Collection of Class objects (may be {@code null})
* @param classes an array of Class objects
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
* @see java.util.AbstractCollection#toString()
*/
Expand Down Expand Up @@ -1231,6 +1231,7 @@ public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
/**
* Check whether the given object is a CGLIB proxy.
* @param object the object to check
* @see #isCglibProxyClass(Class)
* @see org.springframework.aop.support.AopUtils#isCglibProxy(Object)
*/
public static boolean isCglibProxy(Object object) {
Expand All @@ -1240,6 +1241,7 @@ public static boolean isCglibProxy(Object object) {
/**
* Check whether the specified class is a CGLIB-generated class.
* @param clazz the class to check
* @see #isCglibProxyClassName(String)
*/
public static boolean isCglibProxyClass(Class<?> clazz) {
return (clazz != null && isCglibProxyClassName(clazz.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ protected final class Segment extends ReentrantLock {
private final int initialSize;

/**
* Array of references indexed using the low order bits from the hash. This
* property should only be set via {@link #setReferences} to ensure that the
* {@code resizeThreshold} is maintained.
* Array of references indexed using the low order bits from the hash.
* This property should only be set along with {@code resizeThreshold}.
*/
private volatile Reference<K, V>[] references;

Expand Down Expand Up @@ -617,14 +616,14 @@ private void setReferences(Reference<K, V>[] references) {
}

/**
* @return the size of the current references array
* Return the size of the current references array.
*/
public final int getSize() {
return this.references.length;
}

/**
* @return the total number of references in this segment
* Return the total number of references in this segment.
*/
public final int getCount() {
return this.count;
Expand All @@ -639,21 +638,17 @@ public final int getCount() {
protected interface Reference<K, V> {

/**
* Returns the referenced entry or {@code null} if the entry is no longer
* available.
* @return the entry or {@code null}
* Return the referenced entry, or {@code null} if the entry is no longer available.
*/
Entry<K, V> get();

/**
* Returns the hash for the reference.
* @return the hash
* Return the hash for the reference.
*/
int getHash();

/**
* Returns the next reference in the chain or {@code null}
* @return the next reference of {@code null}
* Return the next reference in the chain, or {@code null} if none.
*/
Reference<K, V> getNext();

Expand Down Expand Up @@ -930,7 +925,7 @@ protected class ReferenceManager {
* Factory method used to create a new {@link Reference}.
* @param entry the entry contained in the reference
* @param hash the hash
* @param next the next reference in the chain or {@code null}
* @param next the next reference in the chain, or {@code null} if none
* @return a new {@link Reference}
*/
public Reference<K, V> createReference(Entry<K, V> entry, int hash, Reference<K, V> next) {
Expand Down
Loading

0 comments on commit cc70fdc

Please sign in to comment.