From 7a8f4edf0e997b78670242ca1ed641e5ede2fbda Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 8 Apr 2022 13:03:13 +0200 Subject: [PATCH] Avoid return value reference in potentially cached MethodParameter instance Closes gh-28232 (cherry picked from commit eefdd2c768cbacdc97839ede2209a630cf1f0d3e) --- .../springframework/messaging/handler/HandlerMethod.java | 8 ++++---- .../org/springframework/web/method/HandlerMethod.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java index e89477e70b07..3fb415b4701b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -282,16 +282,16 @@ public T getMethodAnnotation(Class annotationType) { */ private class ReturnValueMethodParameter extends HandlerMethodParameter { - private final Object returnValue; + private final Class returnValueType; public ReturnValueMethodParameter(Object returnValue) { super(-1); - this.returnValue = returnValue; + this.returnValueType = (returnValue != null ? returnValue.getClass() : null); } @Override public Class getParameterType() { - return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType()); + return (this.returnValueType != null ? this.returnValueType : super.getParameterType()); } } diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index a22804c733f3..52c45508c573 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -297,16 +297,16 @@ public T getMethodAnnotation(Class annotationType) { */ private class ReturnValueMethodParameter extends HandlerMethodParameter { - private final Object returnValue; + private final Class returnValueType; public ReturnValueMethodParameter(Object returnValue) { super(-1); - this.returnValue = returnValue; + this.returnValueType = (returnValue != null ? returnValue.getClass() : null); } @Override public Class getParameterType() { - return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType()); + return (this.returnValueType != null ? this.returnValueType : super.getParameterType()); } }