Skip to content

Commit 4886bf0

Browse files
committed
Polishing
1 parent 75e0869 commit 4886bf0

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@
3333
import org.springframework.web.method.HandlerMethodSelector;
3434

3535
/**
36-
* Discovers {@linkplain ExceptionHandler @ExceptionHandler} methods in a given class
37-
* type, including all super types, and helps to resolve an Exception to the method
38-
* its mapped to. Exception mappings are defined through {@code @ExceptionHandler}
39-
* annotation or by looking at the signature of an {@code @ExceptionHandler} method.
36+
* Discovers {@linkplain ExceptionHandler @ExceptionHandler} methods in a given class,
37+
* including all of its superclasses, and helps to resolve a given {@link Exception}
38+
* to the exception types supported by a given {@link Method}.
4039
*
4140
* @author Rossen Stoyanchev
4241
* @since 3.1
@@ -46,12 +45,15 @@ public class ExceptionHandlerMethodResolver {
4645
/**
4746
* A filter for selecting {@code @ExceptionHandler} methods.
4847
*/
49-
public final static MethodFilter EXCEPTION_HANDLER_METHODS = new MethodFilter() {
48+
public static final MethodFilter EXCEPTION_HANDLER_METHODS = new MethodFilter() {
5049
public boolean matches(Method method) {
5150
return (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null);
5251
}
5352
};
5453

54+
/**
55+
* Arbitrary {@link Method} reference, indicating no method found in the cache.
56+
*/
5557
private static final Method NO_METHOD_FOUND = ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis");
5658

5759

@@ -76,8 +78,8 @@ public ExceptionHandlerMethodResolver(Class<?> handlerType) {
7678

7779

7880
/**
79-
* Extract exception mappings from the {@code @ExceptionHandler} annotation
80-
* first and as a fall-back from the method signature.
81+
* Extract exception mappings from the {@code @ExceptionHandler} annotation first,
82+
* and then as a fallback from the method signature itself.
8183
*/
8284
@SuppressWarnings("unchecked")
8385
private List<Class<? extends Throwable>> detectExceptionMappings(Method method) {
@@ -112,36 +114,36 @@ private void addExceptionMapping(Class<? extends Throwable> exceptionType, Metho
112114
* Whether the contained type has any exception mappings.
113115
*/
114116
public boolean hasExceptionMappings() {
115-
return (this.mappedMethods.size() > 0);
117+
return !this.mappedMethods.isEmpty();
116118
}
117119

118120
/**
119-
* Find a method to handle the given exception.
121+
* Find a {@link Method} to handle the given exception.
120122
* Use {@link ExceptionDepthComparator} if more than one match is found.
121123
* @param exception the exception
122-
* @return a method to handle the exception or {@code null}
124+
* @return a Method to handle the exception, or {@code null} if none found
123125
*/
124126
public Method resolveMethod(Exception exception) {
125127
return resolveMethodByExceptionType(exception.getClass());
126128
}
127129

128130
/**
129-
* Find a method to handle the given exception type. This can be useful if
130-
* an Exception instance is not available (example for tools).
131+
* Find a {@link Method} to handle the given exception type. This can be
132+
* useful if an {@link Exception} instance is not available (e.g. for tools).
131133
* @param exceptionType the exception type
132-
* @return a method to handle the exception or {@code null}
134+
* @return a Method to handle the exception, or {@code null} if none found
133135
*/
134136
public Method resolveMethodByExceptionType(Class<? extends Exception> exceptionType) {
135137
Method method = this.exceptionLookupCache.get(exceptionType);
136138
if (method == null) {
137139
method = getMappedMethod(exceptionType);
138-
this.exceptionLookupCache.put(exceptionType, method != null ? method : NO_METHOD_FOUND);
140+
this.exceptionLookupCache.put(exceptionType, (method != null ? method : NO_METHOD_FOUND));
139141
}
140-
return method != NO_METHOD_FOUND ? method : null;
142+
return (method != NO_METHOD_FOUND ? method : null);
141143
}
142144

143145
/**
144-
* Return the method mapped to the given exception type or {@code null}.
146+
* Return the {@link Method} mapped to the given exception type, or {@code null} if none.
145147
*/
146148
private Method getMappedMethod(Class<? extends Exception> exceptionType) {
147149
List<Class<? extends Throwable>> matches = new ArrayList<Class<? extends Throwable>>();

0 commit comments

Comments
 (0)