Skip to content

Commit eefdd2c

Browse files
committed
Avoid return value reference in potentially cached MethodParameter instance
Closes gh-28232
1 parent 9f91168 commit eefdd2c

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-2021 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.
@@ -420,21 +420,21 @@ public HandlerMethodParameter clone() {
420420
private class ReturnValueMethodParameter extends HandlerMethodParameter {
421421

422422
@Nullable
423-
private final Object returnValue;
423+
private final Class<?> returnValueType;
424424

425425
public ReturnValueMethodParameter(@Nullable Object returnValue) {
426426
super(-1);
427-
this.returnValue = returnValue;
427+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
428428
}
429429

430430
protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
431431
super(original);
432-
this.returnValue = original.returnValue;
432+
this.returnValueType = original.returnValueType;
433433
}
434434

435435
@Override
436436
public Class<?> getParameterType() {
437-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
437+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
438438
}
439439

440440
@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-2021 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.
@@ -582,21 +582,21 @@ public HandlerMethodParameter clone() {
582582
private class ReturnValueMethodParameter extends HandlerMethodParameter {
583583

584584
@Nullable
585-
private final Object returnValue;
585+
private final Class<?> returnValueType;
586586

587587
public ReturnValueMethodParameter(@Nullable Object returnValue) {
588588
super(-1);
589-
this.returnValue = returnValue;
589+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
590590
}
591591

592592
protected ReturnValueMethodParameter(ReturnValueMethodParameter original) {
593593
super(original);
594-
this.returnValue = original.returnValue;
594+
this.returnValueType = original.returnValueType;
595595
}
596596

597597
@Override
598598
public Class<?> getParameterType() {
599-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
599+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
600600
}
601601

602602
@Override

0 commit comments

Comments
 (0)