Skip to content

Commit 9fdc440

Browse files
committed
Backport selected refinements from the nullability efforts
Issue: SPR-15656
1 parent 18a3322 commit 9fdc440

File tree

194 files changed

+1231
-1213
lines changed

Some content is hidden

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

194 files changed

+1231
-1213
lines changed

spring-aop/src/main/java/org/springframework/aop/TargetSource.java

Lines changed: 8 additions & 9 deletions
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.
@@ -34,19 +34,17 @@ public interface TargetSource extends TargetClassAware {
3434

3535
/**
3636
* Return the type of targets returned by this {@link TargetSource}.
37-
* <p>Can return {@code null}, although certain usages of a
38-
* {@code TargetSource} might just work with a predetermined
39-
* target class.
37+
* <p>Can return {@code null}, although certain usages of a {@code TargetSource}
38+
* might just work with a predetermined target class.
4039
* @return the type of targets returned by this {@link TargetSource}
4140
*/
4241
@Override
4342
Class<?> getTargetClass();
4443

4544
/**
4645
* Will all calls to {@link #getTarget()} return the same object?
47-
* <p>In that case, there will be no need to invoke
48-
* {@link #releaseTarget(Object)}, and the AOP framework can cache
49-
* the return value of {@link #getTarget()}.
46+
* <p>In that case, there will be no need to invoke {@link #releaseTarget(Object)},
47+
* and the AOP framework can cache the return value of {@link #getTarget()}.
5048
* @return {@code true} if the target is immutable
5149
* @see #getTarget
5250
*/
@@ -55,14 +53,15 @@ public interface TargetSource extends TargetClassAware {
5553
/**
5654
* Return a target instance. Invoked immediately before the
5755
* AOP framework calls the "target" of an AOP method invocation.
58-
* @return the target object, which contains the joinpoint
56+
* @return the target object which contains the joinpoint,
57+
* or {@code null} if there is no actual target instance
5958
* @throws Exception if the target object can't be resolved
6059
*/
6160
Object getTarget() throws Exception;
6261

6362
/**
6463
* Release the given target object obtained from the
65-
* {@link #getTarget()} method.
64+
* {@link #getTarget()} method, if any.
6665
* @param target object obtained from a call to {@link #getTarget()}
6766
* @throws Exception if the object can't be released
6867
*/

spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java

Lines changed: 10 additions & 10 deletions
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.
@@ -103,8 +103,8 @@ public static JoinPoint currentJoinPoint() {
103103
private final AspectInstanceFactory aspectInstanceFactory;
104104

105105
/**
106-
* The name of the aspect (ref bean) in which this advice was defined (used
107-
* when determining advice precedence so that we can determine
106+
* The name of the aspect (ref bean) in which this advice was defined
107+
* (used when determining advice precedence so that we can determine
108108
* whether two pieces of advice come from the same aspect).
109109
*/
110110
private String aspectName;
@@ -118,13 +118,13 @@ public static JoinPoint currentJoinPoint() {
118118
* This will be non-null if the creator of this advice object knows the argument names
119119
* and sets them explicitly
120120
*/
121-
private String[] argumentNames = null;
121+
private String[] argumentNames;
122122

123123
/** Non-null if after throwing advice binds the thrown value */
124-
private String throwingName = null;
124+
private String throwingName;
125125

126126
/** Non-null if after returning advice binds the return value */
127-
private String returningName = null;
127+
private String returningName;
128128

129129
private Class<?> discoveredReturningType = Object.class;
130130

@@ -295,8 +295,8 @@ protected void setReturningNameNoCheck(String name) {
295295
}
296296
catch (Throwable ex) {
297297
throw new IllegalArgumentException("Returning name '" + name +
298-
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
299-
"Root cause: " + ex);
298+
"' is neither a valid argument name nor the fully-qualified " +
299+
"name of a Java type on the classpath. Root cause: " + ex);
300300
}
301301
}
302302
}
@@ -329,8 +329,8 @@ protected void setThrowingNameNoCheck(String name) {
329329
}
330330
catch (Throwable ex) {
331331
throw new IllegalArgumentException("Throwing name '" + name +
332-
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
333-
"Root cause: " + ex);
332+
"' is neither a valid argument name nor the fully-qualified " +
333+
"name of a Java type on the classpath. Root cause: " + ex);
334334
}
335335
}
336336
}

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java

Lines changed: 10 additions & 13 deletions
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.
@@ -113,6 +113,7 @@
113113
* returning {@code null} in the case that the parameter names cannot be discovered.
114114
*
115115
* @author Adrian Colyer
116+
* @author Juergen Hoeller
116117
* @since 2.0
117118
*/
118119
public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {
@@ -154,23 +155,17 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
154155
}
155156

156157

158+
/** The pointcut expression associated with the advice, as a simple String */
159+
private String pointcutExpression;
160+
157161
private boolean raiseExceptions;
158162

159-
/**
160-
* If the advice is afterReturning, and binds the return value, this is the parameter name used.
161-
*/
163+
/** If the advice is afterReturning, and binds the return value, this is the parameter name used */
162164
private String returningName;
163165

164-
/**
165-
* If the advice is afterThrowing, and binds the thrown value, this is the parameter name used.
166-
*/
166+
/** If the advice is afterThrowing, and binds the thrown value, this is the parameter name used */
167167
private String throwingName;
168168

169-
/**
170-
* The pointcut expression associated with the advice, as a simple String.
171-
*/
172-
private String pointcutExpression;
173-
174169
private Class<?>[] argumentTypes;
175170

176171
private String[] parameterNameBindings;
@@ -186,6 +181,7 @@ public AspectJAdviceParameterNameDiscoverer(String pointcutExpression) {
186181
this.pointcutExpression = pointcutExpression;
187182
}
188183

184+
189185
/**
190186
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
191187
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
@@ -213,6 +209,7 @@ public void setThrowingName(String throwingName) {
213209
this.throwingName = throwingName;
214210
}
215211

212+
216213
/**
217214
* Deduce the parameter names for an advice method.
218215
* <p>See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
@@ -474,7 +471,7 @@ else if (numAnnotationSlots == 1) {
474471
* If the token starts meets Java identifier conventions, it's in.
475472
*/
476473
private String maybeExtractVariableName(String candidateToken) {
477-
if (candidateToken == null || candidateToken.equals("")) {
474+
if (!StringUtils.hasLength(candidateToken)) {
478475
return null;
479476
}
480477
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

Lines changed: 2 additions & 5 deletions
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.
@@ -454,10 +454,7 @@ protected Object createProxy(
454454
}
455455

456456
Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
457-
for (Advisor advisor : advisors) {
458-
proxyFactory.addAdvisor(advisor);
459-
}
460-
457+
proxyFactory.addAdvisors(advisors);
461458
proxyFactory.setTargetSource(targetSource);
462459
customizeProxyFactory(proxyFactory);
463460

spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java

Lines changed: 5 additions & 13 deletions
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.
@@ -22,7 +22,6 @@
2222
import org.springframework.aop.MethodMatcher;
2323
import org.springframework.aop.Pointcut;
2424
import org.springframework.util.Assert;
25-
import org.springframework.util.ObjectUtils;
2625

2726
/**
2827
* Convenient class for building up pointcuts. All methods return
@@ -188,21 +187,14 @@ public boolean equals(Object other) {
188187
if (!(other instanceof ComposablePointcut)) {
189188
return false;
190189
}
191-
ComposablePointcut that = (ComposablePointcut) other;
192-
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
193-
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
190+
ComposablePointcut otherPointcut = (ComposablePointcut) other;
191+
return (this.classFilter.equals(otherPointcut.classFilter) &&
192+
this.methodMatcher.equals(otherPointcut.methodMatcher));
194193
}
195194

196195
@Override
197196
public int hashCode() {
198-
int code = 17;
199-
if (this.classFilter != null) {
200-
code = 37 * code + this.classFilter.hashCode();
201-
}
202-
if (this.methodMatcher != null) {
203-
code = 37 * code + this.methodMatcher.hashCode();
204-
}
205-
return code;
197+
return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
206198
}
207199

208200
@Override

spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java

Lines changed: 9 additions & 18 deletions
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.
@@ -22,7 +22,6 @@
2222
import org.springframework.aop.MethodMatcher;
2323
import org.springframework.aop.Pointcut;
2424
import org.springframework.util.Assert;
25-
import org.springframework.util.ObjectUtils;
2625

2726
/**
2827
* Simple Pointcut that looks for a specific Java 5 annotation
@@ -46,16 +45,15 @@ public class AnnotationMatchingPointcut implements Pointcut {
4645
* @param classAnnotationType the annotation type to look for at the class level
4746
*/
4847
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType) {
49-
this.classFilter = new AnnotationClassFilter(classAnnotationType);
50-
this.methodMatcher = MethodMatcher.TRUE;
48+
this(classAnnotationType, false);
5149
}
5250

5351
/**
5452
* Create a new AnnotationMatchingPointcut for the given annotation type.
5553
* @param classAnnotationType the annotation type to look for at the class level
56-
* @param checkInherited whether to explicitly check the superclasses and
57-
* interfaces for the annotation type as well (even if the annotation type
58-
* is not marked as inherited itself)
54+
* @param checkInherited whether to also check the superclasses and interfaces
55+
* as well as meta-annotations for the annotation type
56+
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
5957
*/
6058
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType, boolean checkInherited) {
6159
this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
@@ -109,21 +107,14 @@ public boolean equals(Object other) {
109107
if (!(other instanceof AnnotationMatchingPointcut)) {
110108
return false;
111109
}
112-
AnnotationMatchingPointcut that = (AnnotationMatchingPointcut) other;
113-
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
114-
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
110+
AnnotationMatchingPointcut otherPointcut = (AnnotationMatchingPointcut) other;
111+
return (this.classFilter.equals(otherPointcut.classFilter) &&
112+
this.methodMatcher.equals(otherPointcut.methodMatcher));
115113
}
116114

117115
@Override
118116
public int hashCode() {
119-
int code = 17;
120-
if (this.classFilter != null) {
121-
code = 37 * code + this.classFilter.hashCode();
122-
}
123-
if (this.methodMatcher != null) {
124-
code = 37 * code + this.methodMatcher.hashCode();
125-
}
126-
return code;
117+
return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
127118
}
128119

129120
@Override

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

Lines changed: 3 additions & 5 deletions
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.
@@ -81,8 +81,6 @@ public interface PropertyAccessor {
8181
* (may be a nested path and/or an indexed/mapped property)
8282
* @return the property type for the particular property,
8383
* or {@code null} if not determinable
84-
* @throws InvalidPropertyException if there is no such property or
85-
* if the property isn't readable
8684
* @throws PropertyAccessException if the property was valid but the
8785
* accessor method failed
8886
*/
@@ -95,8 +93,8 @@ public interface PropertyAccessor {
9593
* (may be a nested path and/or an indexed/mapped property)
9694
* @return the property type for the particular property,
9795
* or {@code null} if not determinable
98-
* @throws InvalidPropertyException if there is no such property or
99-
* if the property isn't readable
96+
* @throws PropertyAccessException if the property was valid but the
97+
* accessor method failed
10098
*/
10199
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
102100

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

Lines changed: 17 additions & 17 deletions
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.
@@ -158,6 +158,22 @@ public interface BeanFactory {
158158
*/
159159
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
160160

161+
/**
162+
* Return an instance, which may be shared or independent, of the specified bean.
163+
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
164+
* overriding the specified default arguments (if any) in the bean definition.
165+
* @param name the name of the bean to retrieve
166+
* @param args arguments to use when creating a bean instance using explicit arguments
167+
* (only applied when creating a new instance as opposed to retrieving an existing one)
168+
* @return an instance of the bean
169+
* @throws NoSuchBeanDefinitionException if there is no such bean definition
170+
* @throws BeanDefinitionStoreException if arguments have been given but
171+
* the affected bean isn't a prototype
172+
* @throws BeansException if the bean could not be created
173+
* @since 2.5
174+
*/
175+
Object getBean(String name, Object... args) throws BeansException;
176+
161177
/**
162178
* Return the bean instance that uniquely matches the given object type, if any.
163179
* <p>This method goes into {@link ListableBeanFactory} by-type lookup territory
@@ -175,22 +191,6 @@ public interface BeanFactory {
175191
*/
176192
<T> T getBean(Class<T> requiredType) throws BeansException;
177193

178-
/**
179-
* Return an instance, which may be shared or independent, of the specified bean.
180-
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
181-
* overriding the specified default arguments (if any) in the bean definition.
182-
* @param name the name of the bean to retrieve
183-
* @param args arguments to use when creating a bean instance using explicit arguments
184-
* (only applied when creating a new instance as opposed to retrieving an existing one)
185-
* @return an instance of the bean
186-
* @throws NoSuchBeanDefinitionException if there is no such bean definition
187-
* @throws BeanDefinitionStoreException if arguments have been given but
188-
* the affected bean isn't a prototype
189-
* @throws BeansException if the bean could not be created
190-
* @since 2.5
191-
*/
192-
Object getBean(String name, Object... args) throws BeansException;
193-
194194
/**
195195
* Return an instance, which may be shared or independent, of the specified bean.
196196
* <p>Allows for specifying explicit constructor arguments / factory method arguments,

0 commit comments

Comments
 (0)