84
84
public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExceptionResolver {
85
85
86
86
// dummy method placeholder
87
- private static final Method NO_METHOD_FOUND = ClassUtils .getMethodIfAvailable (System .class , "currentTimeMillis" , null );
88
-
89
- private final Map <Class <?>, Map <Class <? extends Throwable >, Method >> exceptionHandlerCache =
90
- new ConcurrentHashMap <Class <?>, Map <Class <? extends Throwable >, Method >>();
87
+ private static final Method NO_METHOD_FOUND = ClassUtils .getMethodIfAvailable (System .class , "currentTimeMillis" , ( Class <?>[]) null );
88
+
89
+ private final Map <Class <?>, Map <Class <? extends Throwable >, Method >> exceptionHandlerCache =
90
+ new ConcurrentHashMap <Class <?>, Map <Class <? extends Throwable >, Method >>();
91
91
92
92
private WebArgumentResolver [] customArgumentResolvers ;
93
93
@@ -157,7 +157,7 @@ private Method findBestExceptionHandlerMethod(Object handler, final Exception th
157
157
final Class <?> handlerType = ClassUtils .getUserClass (handler );
158
158
final Class <? extends Throwable > thrownExceptionType = thrownException .getClass ();
159
159
Method handlerMethod = null ;
160
-
160
+
161
161
Map <Class <? extends Throwable >, Method > handlers = exceptionHandlerCache .get (handlerType );
162
162
163
163
if (handlers != null ) {
@@ -170,7 +170,7 @@ private Method findBestExceptionHandlerMethod(Object handler, final Exception th
170
170
handlers = new ConcurrentHashMap <Class <? extends Throwable >, Method >();
171
171
exceptionHandlerCache .put (handlerType , handlers );
172
172
}
173
-
173
+
174
174
final Map <Class <? extends Throwable >, Method > resolverMethods = handlers ;
175
175
176
176
ReflectionUtils .doWithMethods (handlerType , new ReflectionUtils .MethodCallback () {
@@ -228,19 +228,19 @@ protected List<Class<? extends Throwable>> getHandledExceptions(Method method) {
228
228
}
229
229
230
230
/**
231
- * Returns the best matching method. Uses the {@link DepthComparator}.
231
+ * Uses the {@link DepthComparator} to find the best matching method
232
+ * @return the best matching method or {@code null}.
232
233
*/
233
234
private Method getBestMatchingMethod (
234
235
Map <Class <? extends Throwable >, Method > resolverMethods , Exception thrownException ) {
235
236
236
- if (!resolverMethods .isEmpty ()) {
237
- Class <? extends Throwable > closestMatch =
238
- ExceptionDepthComparator .findClosestMatch (resolverMethods .keySet (), thrownException );
239
- return resolverMethods .get (closestMatch );
240
- }
241
- else {
237
+ if (resolverMethods .isEmpty ()) {
242
238
return null ;
243
239
}
240
+ Class <? extends Throwable > closestMatch =
241
+ ExceptionDepthComparator .findClosestMatch (resolverMethods .keySet (), thrownException );
242
+ Method method = resolverMethods .get (closestMatch );
243
+ return ((method == null ) || (NO_METHOD_FOUND == method )) ? null : method ;
244
244
}
245
245
246
246
/**
@@ -249,13 +249,13 @@ private Method getBestMatchingMethod(
249
249
private Object [] resolveHandlerArguments (Method handlerMethod , Object handler ,
250
250
NativeWebRequest webRequest , Exception thrownException ) throws Exception {
251
251
252
- Class [] paramTypes = handlerMethod .getParameterTypes ();
252
+ Class <?> [] paramTypes = handlerMethod .getParameterTypes ();
253
253
Object [] args = new Object [paramTypes .length ];
254
254
Class <?> handlerType = handler .getClass ();
255
255
for (int i = 0 ; i < args .length ; i ++) {
256
256
MethodParameter methodParam = new MethodParameter (handlerMethod , i );
257
257
GenericTypeResolver .resolveParameterType (methodParam , handlerType );
258
- Class paramType = methodParam .getParameterType ();
258
+ Class <?> paramType = methodParam .getParameterType ();
259
259
Object argValue = resolveCommonArgument (methodParam , webRequest , thrownException );
260
260
if (argValue != WebArgumentResolver .UNRESOLVED ) {
261
261
args [i ] = argValue ;
@@ -290,7 +290,7 @@ protected Object resolveCommonArgument(MethodParameter methodParameter, NativeWe
290
290
}
291
291
292
292
// Resolution of standard parameter types...
293
- Class paramType = methodParameter .getParameterType ();
293
+ Class <?> paramType = methodParameter .getParameterType ();
294
294
Object value = resolveStandardArgument (paramType , webRequest , thrownException );
295
295
if (value != WebArgumentResolver .UNRESOLVED && !ClassUtils .isAssignableValue (paramType , value )) {
296
296
throw new IllegalStateException (
@@ -311,7 +311,7 @@ protected Object resolveCommonArgument(MethodParameter methodParameter, NativeWe
311
311
* @param thrownException the exception thrown
312
312
* @return the argument value, or {@link WebArgumentResolver#UNRESOLVED}
313
313
*/
314
- protected Object resolveStandardArgument (Class parameterType , NativeWebRequest webRequest ,
314
+ protected Object resolveStandardArgument (Class <?> parameterType , NativeWebRequest webRequest ,
315
315
Exception thrownException ) throws Exception {
316
316
317
317
if (parameterType .isInstance (thrownException )) {
@@ -395,7 +395,7 @@ else if (returnValue instanceof Model) {
395
395
return new ModelAndView ().addAllObjects (((Model ) returnValue ).asMap ());
396
396
}
397
397
else if (returnValue instanceof Map ) {
398
- return new ModelAndView ().addAllObjects ((Map ) returnValue );
398
+ return new ModelAndView ().addAllObjects ((Map < String , Object > ) returnValue );
399
399
}
400
400
else if (returnValue instanceof View ) {
401
401
return new ModelAndView ((View ) returnValue );
0 commit comments