Skip to content

Commit 2496d68

Browse files
committed
Relaxed final declarations and protected doInvoke methods
Issue: SPR-12484
1 parent efb114d commit 2496d68

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
import org.springframework.util.ReflectionUtils;
3030

3131
/**
32-
* Invokes the handler method for a given message after resolving
33-
* its method argument values through registered {@link HandlerMethodArgumentResolver}s.
32+
* Invokes the handler method for a given message after resolving its method argument
33+
* values through registered {@link HandlerMethodArgumentResolver}s.
3434
*
3535
* <p>Use {@link #setMessageMethodArgumentResolvers(HandlerMethodArgumentResolver)}
3636
* to customize the list of argument resolvers.
3737
*
3838
* @author Rossen Stoyanchev
39+
* @author Juergen Hoeller
3940
* @since 4.0
4041
*/
4142
public class InvocableHandlerMethod extends HandlerMethod {
@@ -66,7 +67,9 @@ public InvocableHandlerMethod(Object bean, Method method) {
6667
* @param parameterTypes the method parameter types
6768
* @throws NoSuchMethodException when the method cannot be found
6869
*/
69-
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
70+
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
71+
throws NoSuchMethodException {
72+
7073
super(bean, methodName, parameterTypes);
7174
}
7275

@@ -93,12 +96,12 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
9396
* @throws Exception raised if no suitable argument resolver can be found,
9497
* or the method raised an exception
9598
*/
96-
public final Object invoke(Message<?> message, Object... providedArgs) throws Exception {
99+
public Object invoke(Message<?> message, Object... providedArgs) throws Exception {
97100
Object[] args = getMethodArgumentValues(message, providedArgs);
98101
if (logger.isTraceEnabled()) {
99102
logger.trace("Resolved arguments: " + Arrays.asList(args));
100103
}
101-
Object returnValue = invoke(args);
104+
Object returnValue = doInvoke(args);
102105
if (logger.isTraceEnabled()) {
103106
logger.trace("Returned value: " + returnValue);
104107
}
@@ -172,10 +175,11 @@ private Object resolveProvidedArgument(MethodParameter parameter, Object... prov
172175
return null;
173176
}
174177

178+
175179
/**
176180
* Invoke the handler method with the given argument values.
177181
*/
178-
private Object invoke(Object... args) throws Exception {
182+
protected Object doInvoke(Object... args) throws Exception {
179183
ReflectionUtils.makeAccessible(getBridgedMethod());
180184
try {
181185
return getBridgedMethod().invoke(getBean(), args);

spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@
3232
import org.springframework.web.method.HandlerMethod;
3333

3434
/**
35-
* Provides a method for invoking the handler method for a given request after resolving its method argument
36-
* values through registered {@link HandlerMethodArgumentResolver}s.
35+
* Provides a method for invoking the handler method for a given request after resolving its
36+
* method argument values through registered {@link HandlerMethodArgumentResolver}s.
3737
*
38-
* <p>Argument resolution often requires a {@link WebDataBinder} for data binding or for type conversion.
39-
* Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply a binder factory to pass to
40-
* argument resolvers.
38+
* <p>Argument resolution often requires a {@link WebDataBinder} for data binding or for type
39+
* conversion. Use the {@link #setDataBinderFactory(WebDataBinderFactory)} property to supply
40+
* a binder factory to pass to argument resolvers.
4141
*
42-
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)} to customize
43-
* the list of argument resolvers.
42+
* <p>Use {@link #setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite)}
43+
* to customize the list of argument resolvers.
4444
*
4545
* @author Rossen Stoyanchev
46+
* @author Juergen Hoeller
4647
* @since 3.1
4748
*/
4849
public class InvocableHandlerMethod extends HandlerMethod {
@@ -75,7 +76,9 @@ public InvocableHandlerMethod(HandlerMethod handlerMethod) {
7576
* @param parameterTypes the method parameter types
7677
* @throws NoSuchMethodException when the method cannot be found
7778
*/
78-
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
79+
public InvocableHandlerMethod(Object bean, String methodName, Class<?>... parameterTypes)
80+
throws NoSuchMethodException {
81+
7982
super(bean, methodName, parameterTypes);
8083
}
8184

@@ -107,18 +110,20 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
107110

108111

109112
/**
110-
* Invoke the method after resolving its argument values in the context of the given request. <p>Argument
111-
* values are commonly resolved through {@link HandlerMethodArgumentResolver}s. The {@code provideArgs}
112-
* parameter however may supply argument values to be used directly, i.e. without argument resolution.
113-
* Examples of provided argument values include a {@link WebDataBinder}, a {@link SessionStatus}, or
114-
* a thrown exception instance. Provided argument values are checked before argument resolvers.
113+
* Invoke the method after resolving its argument values in the context of the given request.
114+
* <p>Argument values are commonly resolved through {@link HandlerMethodArgumentResolver}s.
115+
* The {@code provideArgs} parameter however may supply argument values to be used directly,
116+
* i.e. without argument resolution. Examples of provided argument values include a
117+
* {@link WebDataBinder}, a {@link SessionStatus}, or a thrown exception instance.
118+
* Provided argument values are checked before argument resolvers.
115119
* @param request the current request
116120
* @param mavContainer the ModelAndViewContainer for this request
117121
* @param providedArgs "given" arguments matched by type, not resolved
118122
* @return the raw value returned by the invoked method
119-
* @exception Exception raised if no suitable argument resolver can be found, or the method raised an exception
123+
* @exception Exception raised if no suitable argument resolver can be found,
124+
* or if the method raised an exception
120125
*/
121-
public final Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
126+
public Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer,
122127
Object... providedArgs) throws Exception {
123128

124129
Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs);
@@ -129,7 +134,7 @@ public final Object invokeForRequest(NativeWebRequest request, ModelAndViewConta
129134
sb.append(Arrays.asList(args));
130135
logger.trace(sb.toString());
131136
}
132-
Object returnValue = invoke(args);
137+
Object returnValue = doInvoke(args);
133138
if (logger.isTraceEnabled()) {
134139
logger.trace("Method [" + getMethod().getName() + "] returned [" + returnValue + "]");
135140
}
@@ -206,10 +211,11 @@ private Object resolveProvidedArgument(MethodParameter parameter, Object... prov
206211
return null;
207212
}
208213

214+
209215
/**
210216
* Invoke the handler method with the given argument values.
211217
*/
212-
private Object invoke(Object... args) throws Exception {
218+
protected Object doInvoke(Object... args) throws Exception {
213219
ReflectionUtils.makeAccessible(getBridgedMethod());
214220
try {
215221
return getBridgedMethod().invoke(getBean(), args);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private void initResponseStatus() {
8888
}
8989
}
9090

91+
9192
/**
9293
* Register {@link HandlerMethodReturnValueHandler} instances to use to
9394
* handle return values.
@@ -99,16 +100,14 @@ public void setHandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerC
99100
/**
100101
* Invokes the method and handles the return value through one of the
101102
* configured {@link HandlerMethodReturnValueHandler}s.
102-
*
103103
* @param webRequest the current request
104104
* @param mavContainer the ModelAndViewContainer for this request
105-
* @param providedArgs "given" arguments matched by type, not resolved
105+
* @param providedArgs "given" arguments matched by type (not resolved)
106106
*/
107-
public final void invokeAndHandle(ServletWebRequest webRequest,
107+
public void invokeAndHandle(ServletWebRequest webRequest,
108108
ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception {
109109

110110
Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs);
111-
112111
setResponseStatus(webRequest);
113112

114113
if (returnValue == null) {
@@ -123,9 +122,9 @@ else if (StringUtils.hasText(this.responseReason)) {
123122
}
124123

125124
mavContainer.setRequestHandled(false);
126-
127125
try {
128-
this.returnValueHandlers.handleReturnValue(returnValue, getReturnValueType(returnValue), mavContainer, webRequest);
126+
this.returnValueHandlers.handleReturnValue(
127+
returnValue, getReturnValueType(returnValue), mavContainer, webRequest);
129128
}
130129
catch (Exception ex) {
131130
if (logger.isTraceEnabled()) {
@@ -165,20 +164,20 @@ private boolean isRequestNotModified(ServletWebRequest webRequest) {
165164
* Does this method have the response status instruction?
166165
*/
167166
private boolean hasResponseStatus() {
168-
return this.responseStatus != null;
167+
return (this.responseStatus != null);
169168
}
170169

171170
private String getReturnValueHandlingErrorMessage(String message, Object returnValue) {
172171
StringBuilder sb = new StringBuilder(message);
173172
if (returnValue != null) {
174-
sb.append(" [type=" + returnValue.getClass().getName() + "] ");
173+
sb.append(" [type=").append(returnValue.getClass().getName()).append("]");
175174
}
176-
sb.append("[value=" + returnValue + "]");
175+
sb.append(" [value=").append(returnValue).append("]");
177176
return getDetailedErrorMessage(sb.toString());
178177
}
179178

180179
/**
181-
* Create a nested ServletInvocableHandlerMethod sub-class that returns the
180+
* Create a nested ServletInvocableHandlerMethod subclass that returns the
182181
* the given value (or raises an Exception if the value is one) rather than
183182
* actually invoking the controller method. This is useful when processing
184183
* async return values (e.g. Callable, DeferredResult, ListenableFuture).
@@ -189,7 +188,7 @@ ServletInvocableHandlerMethod wrapConcurrentResult(Object result) {
189188

190189

191190
/**
192-
* A nested sub-class of {@code ServletInvocableHandlerMethod} that uses a
191+
* A nested subclass of {@code ServletInvocableHandlerMethod} that uses a
193192
* simple {@link Callable} instead of the original controller as the handler in
194193
* order to return the fixed (concurrent) result value given to it. Effectively
195194
* "resumes" processing with the asynchronously produced return value.
@@ -198,7 +197,6 @@ private class ConcurrentResultHandlerMethod extends ServletInvocableHandlerMetho
198197

199198
private final MethodParameter returnType;
200199

201-
202200
public ConcurrentResultHandlerMethod(final Object result, ConcurrentResultMethodParameter returnType) {
203201
super(new Callable<Object>() {
204202
@Override
@@ -242,8 +240,9 @@ public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType) {
242240
}
243241
}
244242

243+
245244
/**
246-
* MethodParameter sub-class based on the actual return value type or if
245+
* MethodParameter subclass based on the actual return value type or if
247246
* that's null falling back on the generic type within the declared async
248247
* return type, e.g. Foo instead of {@code DeferredResult<Foo>}.
249248
*/
@@ -253,7 +252,6 @@ private class ConcurrentResultMethodParameter extends HandlerMethodParameter {
253252

254253
private final ResolvableType returnType;
255254

256-
257255
public ConcurrentResultMethodParameter(Object returnValue) {
258256
super(-1);
259257
this.returnValue = returnValue;
@@ -262,7 +260,7 @@ public ConcurrentResultMethodParameter(Object returnValue) {
262260

263261
@Override
264262
public Class<?> getParameterType() {
265-
return (returnValue != null ? returnValue.getClass() : this.returnType.getRawClass());
263+
return (this.returnValue != null ? this.returnValue.getClass() : this.returnType.getRawClass());
266264
}
267265

268266
@Override

0 commit comments

Comments
 (0)