Skip to content

Commit 5cbf85a

Browse files
committed
Avoid return value reference in potentially cached MethodParameter instance
Closes gh-28232 (cherry picked from commit eefdd2c)
1 parent 69c7eb9 commit 5cbf85a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -416,21 +416,21 @@ public HandlerMethodParameter clone() {
416416
private class ReturnValueMethodParameter extends HandlerMethodParameter {
417417

418418
@Nullable
419-
private final Object returnValue;
419+
private final Class<?> returnValueType;
420420

421421
public ReturnValueMethodParameter(@Nullable Object returnValue) {
422422
super(-1);
423-
this.returnValue = returnValue;
423+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
424424
}
425425

426426
protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
427427
super(original);
428-
this.returnValue = original.returnValue;
428+
this.returnValueType = original.returnValueType;
429429
}
430430

431431
@Override
432432
public Class<?> getParameterType() {
433-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
433+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
434434
}
435435

436436
@Override

spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -536,21 +536,21 @@ public HandlerMethodParameter clone() {
536536
private class ReturnValueMethodParameter extends HandlerMethodParameter {
537537

538538
@Nullable
539-
private final Object returnValue;
539+
private final Class<?> returnValueType;
540540

541541
public ReturnValueMethodParameter(@Nullable Object returnValue) {
542542
super(-1);
543-
this.returnValue = returnValue;
543+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
544544
}
545545

546546
protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
547547
super(original);
548-
this.returnValue = original.returnValue;
548+
this.returnValueType = original.returnValueType;
549549
}
550550

551551
@Override
552552
public Class<?> getParameterType() {
553-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
553+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
554554
}
555555

556556
@Override

0 commit comments

Comments
 (0)