Skip to content

Commit cc70fdc

Browse files
committed
Backport further refinements from the nullability efforts
Issue: SPR-15656
1 parent 5f167fd commit cc70fdc

File tree

50 files changed

+382
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+382
-532
lines changed

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,10 +55,10 @@
5555
* as String arrays are converted in such a format if the array itself is not
5656
* assignable.
5757
*
58-
* @author Rod Johnson
5958
* @author Juergen Hoeller
60-
* @author Rob Harrop
6159
* @author Stephane Nicoll
60+
* @author Rod Johnson
61+
* @author Rob Harrop
6262
* @since 4.2
6363
* @see #registerCustomEditor
6464
* @see #setPropertyValues
@@ -96,9 +96,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
9696

9797
Object rootObject;
9898

99-
/**
100-
* Map with cached nested Accessors: nested path -> Accessor instance.
101-
*/
99+
/** Map with cached nested Accessors: nested path -> Accessor instance */
102100
private Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors;
103101

104102

spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,8 +46,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
4646
public CannotLoadBeanClassException(
4747
String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) {
4848

49-
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName +
50-
"' defined in " + resourceDescription, cause);
49+
super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
50+
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
5151
this.resourceDescription = resourceDescription;
5252
this.beanName = beanName;
5353
this.beanClassName = beanClassName;
@@ -64,8 +64,9 @@ public CannotLoadBeanClassException(
6464
public CannotLoadBeanClassException(
6565
String resourceDescription, String beanName, String beanClassName, LinkageError cause) {
6666

67-
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName +
68-
"' defined in " + resourceDescription + ": problem with class file or dependent class", cause);
67+
super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
68+
(resourceDescription != null ? " defined in " + resourceDescription : "") +
69+
": problem with class file or dependent class", cause);
6970
this.resourceDescription = resourceDescription;
7071
this.beanName = beanName;
7172
this.beanClassName = beanClassName;

spring-beans/src/main/java/org/springframework/beans/factory/config/DependencyDescriptor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ public void setContainingClass(Class<?> containingClass) {
240240
* @since 4.0
241241
*/
242242
public ResolvableType getResolvableType() {
243-
if (this.resolvableType == null) {
244-
this.resolvableType = (this.field != null ?
243+
ResolvableType resolvableType = this.resolvableType;
244+
if (resolvableType == null) {
245+
resolvableType = (this.field != null ?
245246
ResolvableType.forField(this.field, this.nestingLevel, this.containingClass) :
246247
ResolvableType.forMethodParameter(this.methodParameter));
248+
this.resolvableType = resolvableType;
247249
}
248-
return this.resolvableType;
250+
return resolvableType;
249251
}
250252

251253
/**

spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
import org.springframework.core.ResolvableType;
3636
import org.springframework.core.annotation.AnnotationUtils;
3737
import org.springframework.util.Assert;
38+
import org.springframework.util.ObjectUtils;
3839
import org.springframework.util.StringUtils;
3940

4041
/**
@@ -134,12 +135,21 @@ public Object getBean(String name) throws BeansException {
134135
@SuppressWarnings("unchecked")
135136
public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
136137
Object bean = getBean(name);
137-
if (requiredType != null && !requiredType.isAssignableFrom(bean.getClass())) {
138+
if (requiredType != null && !requiredType.isInstance(bean)) {
138139
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
139140
}
140141
return (T) bean;
141142
}
142143

144+
@Override
145+
public Object getBean(String name, Object... args) throws BeansException {
146+
if (!ObjectUtils.isEmpty(args)) {
147+
throw new UnsupportedOperationException(
148+
"StaticListableBeanFactory does not support explicit bean creation arguments");
149+
}
150+
return getBean(name);
151+
}
152+
143153
@Override
144154
public <T> T getBean(Class<T> requiredType) throws BeansException {
145155
String[] beanNames = getBeanNamesForType(requiredType);
@@ -154,18 +164,9 @@ else if (beanNames.length > 1) {
154164
}
155165
}
156166

157-
@Override
158-
public Object getBean(String name, Object... args) throws BeansException {
159-
if (args != null) {
160-
throw new UnsupportedOperationException(
161-
"StaticListableBeanFactory does not support explicit bean creation arguments");
162-
}
163-
return getBean(name);
164-
}
165-
166167
@Override
167168
public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
168-
if (args != null) {
169+
if (!ObjectUtils.isEmpty(args)) {
169170
throw new UnsupportedOperationException(
170171
"StaticListableBeanFactory does not support explicit bean creation arguments");
171172
}
@@ -352,7 +353,8 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an
352353
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
353354
throws NoSuchBeanDefinitionException{
354355

355-
return AnnotationUtils.findAnnotation(getType(beanName), annotationType);
356+
Class<?> beanType = getType(beanName);
357+
return (beanType != null ? AnnotationUtils.findAnnotation(beanType, annotationType) : null);
356358
}
357359

358360
}

spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -140,7 +140,7 @@ protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefin
140140
/**
141141
* Central template method to actually parse the supplied {@link Element}
142142
* into one or more {@link BeanDefinition BeanDefinitions}.
143-
* @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
143+
* @param element the element that is to be parsed into one or more {@link BeanDefinition BeanDefinitions}
144144
* @param parserContext the object encapsulating the current state of the parsing process;
145145
* provides access to a {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
146146
* @return the primary {@link BeanDefinition} resulting from the parsing of the supplied {@link Element}

spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ else if (parentDefaults != null) {
389389
}
390390

391391
/**
392-
* Return the defaults definition object, or {@code null} if the
393-
* defaults have been initialized yet.
392+
* Return the defaults definition object.
394393
*/
395394
public DocumentDefaultsDefinition getDefaults() {
396395
return this.defaults;

spring-context/src/main/java/org/springframework/context/annotation/ConditionContext.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,43 +25,39 @@
2525
* Context information for use by {@link Condition}s.
2626
*
2727
* @author Phillip Webb
28+
* @author Juergen Hoeller
2829
* @since 4.0
2930
*/
3031
public interface ConditionContext {
3132

3233
/**
3334
* Return the {@link BeanDefinitionRegistry} that will hold the bean definition
34-
* should the condition match or {@code null} if the registry is not available.
35-
* @return the registry or {@code null}
35+
* should the condition match, or {@code null} if the registry is not available.
3636
*/
3737
BeanDefinitionRegistry getRegistry();
3838

3939
/**
4040
* Return the {@link ConfigurableListableBeanFactory} that will hold the bean
41-
* definition should the condition match or {@code null} if the bean factory
41+
* definition should the condition match, or {@code null} if the bean factory
4242
* is not available.
43-
* @return the bean factory or {@code null}
4443
*/
4544
ConfigurableListableBeanFactory getBeanFactory();
4645

4746
/**
48-
* Return the {@link Environment} for which the current application is running
47+
* Return the {@link Environment} for which the current application is running,
4948
* or {@code null} if no environment is available.
50-
* @return the environment or {@code null}
5149
*/
5250
Environment getEnvironment();
5351

5452
/**
55-
* Return the {@link ResourceLoader} currently being used or {@code null}
56-
* if the resource loader cannot be obtained.
57-
* @return a resource loader or {@code null}
53+
* Return the {@link ResourceLoader} currently being used, or {@code null} if
54+
* the resource loader cannot be obtained.
5855
*/
5956
ResourceLoader getResourceLoader();
6057

6158
/**
62-
* Return the {@link ClassLoader} that should be used to load additional
63-
* classes or {@code null} if the default classloader should be used.
64-
* @return the class loader or {@code null}
59+
* Return the {@link ClassLoader} that should be used to load additional classes,
60+
* or {@code null} if the default classloader should be used.
6561
*/
6662
ClassLoader getClassLoader();
6763

spring-context/src/test/java/org/springframework/jmx/IJmxTestBean.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,19 +22,19 @@
2222
*/
2323
public interface IJmxTestBean {
2424

25-
public int add(int x, int y);
25+
int add(int x, int y);
2626

27-
public long myOperation();
27+
long myOperation();
2828

29-
public int getAge();
29+
int getAge();
3030

31-
public void setAge(int age);
31+
void setAge(int age);
3232

33-
public void setName(String name) throws Exception;
33+
void setName(String name) throws Exception;
3434

35-
public String getName();
35+
String getName();
3636

3737
// used to test invalid methods that exist in the proxy interface
38-
public void dontExposeMe();
38+
void dontExposeMe();
3939

4040
}

spring-core/src/main/java/org/springframework/util/ClassUtils.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ public static String classPackageAsResourcePath(Class<?> clazz) {
10301030
* in the given array.
10311031
* <p>Basically like {@code AbstractCollection.toString()}, but stripping
10321032
* the "class "/"interface " prefix before every class name.
1033-
* @param classes a Collection of Class objects (may be {@code null})
1033+
* @param classes an array of Class objects
10341034
* @return a String of form "[com.foo.Bar, com.foo.Baz]"
10351035
* @see java.util.AbstractCollection#toString()
10361036
*/
@@ -1231,6 +1231,7 @@ public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {
12311231
/**
12321232
* Check whether the given object is a CGLIB proxy.
12331233
* @param object the object to check
1234+
* @see #isCglibProxyClass(Class)
12341235
* @see org.springframework.aop.support.AopUtils#isCglibProxy(Object)
12351236
*/
12361237
public static boolean isCglibProxy(Object object) {
@@ -1240,6 +1241,7 @@ public static boolean isCglibProxy(Object object) {
12401241
/**
12411242
* Check whether the specified class is a CGLIB-generated class.
12421243
* @param clazz the class to check
1244+
* @see #isCglibProxyClassName(String)
12431245
*/
12441246
public static boolean isCglibProxyClass(Class<?> clazz) {
12451247
return (clazz != null && isCglibProxyClassName(clazz.getName()));

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,8 @@ protected final class Segment extends ReentrantLock {
419419
private final int initialSize;
420420

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

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

619618
/**
620-
* @return the size of the current references array
619+
* Return the size of the current references array.
621620
*/
622621
public final int getSize() {
623622
return this.references.length;
624623
}
625624

626625
/**
627-
* @return the total number of references in this segment
626+
* Return the total number of references in this segment.
628627
*/
629628
public final int getCount() {
630629
return this.count;
@@ -639,21 +638,17 @@ public final int getCount() {
639638
protected interface Reference<K, V> {
640639

641640
/**
642-
* Returns the referenced entry or {@code null} if the entry is no longer
643-
* available.
644-
* @return the entry or {@code null}
641+
* Return the referenced entry, or {@code null} if the entry is no longer available.
645642
*/
646643
Entry<K, V> get();
647644

648645
/**
649-
* Returns the hash for the reference.
650-
* @return the hash
646+
* Return the hash for the reference.
651647
*/
652648
int getHash();
653649

654650
/**
655-
* Returns the next reference in the chain or {@code null}
656-
* @return the next reference of {@code null}
651+
* Return the next reference in the chain, or {@code null} if none.
657652
*/
658653
Reference<K, V> getNext();
659654

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

0 commit comments

Comments
 (0)