Skip to content
Permalink
Browse files

Defensive resolution of getParameterType (actually never returning null)

Includes defensive access to volatile field for resolved parameter type.

Issue: SPR-16072
  • Loading branch information...
jhoeller committed Oct 16, 2017
1 parent 03be809 commit c2438cb932fd4948a065254854519667e443d396
Showing with 18 additions and 12 deletions.
  1. +18 −12 spring-core/src/main/java/org/springframework/core/MethodParameter.java
@@ -358,17 +358,20 @@ void setParameterType(Class<?> parameterType) {
* @return the parameter type (never {@code null})
*/
public Class<?> getParameterType() {
if (this.parameterType == null) {
Class<?> paramType = this.parameterType;
if (paramType == null) {
if (this.parameterIndex < 0) {
this.parameterType = (this.method != null ? this.method.getReturnType() : null);
Method method = getMethod();
paramType = (method != null ? method.getReturnType() : void.class);
}
else {
this.parameterType = (this.method != null ?
this.method.getParameterTypes()[this.parameterIndex] :
this.constructor.getParameterTypes()[this.parameterIndex]);
paramType = (this.method != null ?
this.method.getParameterTypes()[this.parameterIndex] :
this.constructor.getParameterTypes()[this.parameterIndex]);
}
this.parameterType = paramType;
}
return this.parameterType;
return paramType;
}

/**
@@ -377,17 +380,20 @@ void setParameterType(Class<?> parameterType) {
* @since 3.0
*/
public Type getGenericParameterType() {
if (this.genericParameterType == null) {
Type paramType = this.genericParameterType;
if (paramType == null) {
if (this.parameterIndex < 0) {
this.genericParameterType = (this.method != null ? this.method.getGenericReturnType() : null);
Method method = getMethod();
paramType = (method != null ? method.getGenericReturnType() : void.class);
}
else {
this.genericParameterType = (this.method != null ?
this.method.getGenericParameterTypes()[this.parameterIndex] :
this.constructor.getGenericParameterTypes()[this.parameterIndex]);
paramType = (this.method != null ?
this.method.getGenericParameterTypes()[this.parameterIndex] :
this.constructor.getGenericParameterTypes()[this.parameterIndex]);
}
this.genericParameterType = paramType;
}
return this.genericParameterType;
return paramType;
}

/**

0 comments on commit c2438cb

Please sign in to comment.
You can’t perform that action at this time.