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 gh-28232

(cherry picked from commit eefdd2c)
  • Loading branch information
jhoeller committed Apr 8, 2022
1 parent 69c7eb9 commit 5cbf85a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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 @@ -416,21 +416,21 @@ public HandlerMethodParameter clone() {
private class ReturnValueMethodParameter extends HandlerMethodParameter {

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

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

protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
super(original);
this.returnValue = original.returnValue;
this.returnValueType = original.returnValueType;
}

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

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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 @@ -536,21 +536,21 @@ public HandlerMethodParameter clone() {
private class ReturnValueMethodParameter extends HandlerMethodParameter {

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

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

protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
super(original);
this.returnValue = original.returnValue;
this.returnValueType = original.returnValueType;
}

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

@Override
Expand Down

0 comments on commit 5cbf85a

Please sign in to comment.