Skip to content

Commit a45c399

Browse files
jhoellerBenjamin Reed
authored and
Benjamin Reed
committed
Avoid return value reference in potentially cached MethodParameter instance
Closes spring-projectsgh-28232 (cherry picked from commit eefdd2c)
1 parent fd51809 commit a45c399

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -270,16 +270,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
270270
*/
271271
private class ReturnValueMethodParameter extends HandlerMethodParameter {
272272

273-
private final Object returnValue;
273+
private final Class<?> returnValueType;
274274

275275
public ReturnValueMethodParameter(Object returnValue) {
276276
super(-1);
277-
this.returnValue = returnValue;
277+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
278278
}
279279

280280
@Override
281281
public Class<?> getParameterType() {
282-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
282+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
283283
}
284284
}
285285

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -270,16 +270,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
270270
*/
271271
private class ReturnValueMethodParameter extends HandlerMethodParameter {
272272

273-
private final Object returnValue;
273+
private final Class<?> returnValueType;
274274

275275
public ReturnValueMethodParameter(Object returnValue) {
276276
super(-1);
277-
this.returnValue = returnValue;
277+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
278278
}
279279

280280
@Override
281281
public Class<?> getParameterType() {
282-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
282+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
283283
}
284284
}
285285

0 commit comments

Comments
 (0)