Skip to content

Commit

Permalink
Avoid return value reference in potentially cached MethodParameter in…
Browse files Browse the repository at this point in the history
…stance

Closes spring-projectsgh-28232

(cherry picked from commit eefdd2c)
  • Loading branch information
jhoeller authored and Benjamin Reed committed Jul 26, 2022
1 parent 6d656a4 commit 07ae85f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2022 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 @@ -281,16 +281,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
*/
private class ReturnValueMethodParameter extends HandlerMethodParameter {

private final Object returnValue;
private final Class<?> returnValueType;

public ReturnValueMethodParameter(Object returnValue) {
super(-1);
this.returnValue = returnValue;
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
}

@Override
public Class<?> getParameterType() {
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2022 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 @@ -276,16 +276,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
*/
private class ReturnValueMethodParameter extends HandlerMethodParameter {

private final Object returnValue;
private final Class<?> returnValueType;

public ReturnValueMethodParameter(Object returnValue) {
super(-1);
this.returnValue = returnValue;
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
}

@Override
public Class<?> getParameterType() {
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
}
}

Expand Down

0 comments on commit 07ae85f

Please sign in to comment.