Skip to content

Commit 07ae85f

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 6d656a4 commit 07ae85f

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-2015 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.
@@ -281,16 +281,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
281281
*/
282282
private class ReturnValueMethodParameter extends HandlerMethodParameter {
283283

284-
private final Object returnValue;
284+
private final Class<?> returnValueType;
285285

286286
public ReturnValueMethodParameter(Object returnValue) {
287287
super(-1);
288-
this.returnValue = returnValue;
288+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
289289
}
290290

291291
@Override
292292
public Class<?> getParameterType() {
293-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
293+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
294294
}
295295
}
296296

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-2015 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.
@@ -276,16 +276,16 @@ public <T extends Annotation> T getMethodAnnotation(Class<T> annotationType) {
276276
*/
277277
private class ReturnValueMethodParameter extends HandlerMethodParameter {
278278

279-
private final Object returnValue;
279+
private final Class<?> returnValueType;
280280

281281
public ReturnValueMethodParameter(Object returnValue) {
282282
super(-1);
283-
this.returnValue = returnValue;
283+
this.returnValueType = (returnValue != null ? returnValue.getClass() : null);
284284
}
285285

286286
@Override
287287
public Class<?> getParameterType() {
288-
return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType());
288+
return (this.returnValueType != null ? this.returnValueType : super.getParameterType());
289289
}
290290
}
291291

0 commit comments

Comments
 (0)