Skip to content

Commit 570bdbd

Browse files
committed
Avoid unnecessary sorting in base ExceptionHandlerMethodResolvers
1 parent b587a16 commit 570bdbd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*
3535
* @author Rossen Stoyanchev
3636
* @author Juergen Hoeller
37+
* @author Sam Brannen
3738
* @since 4.0
3839
*/
3940
public abstract class AbstractExceptionHandlerMethodResolver {
@@ -138,7 +139,9 @@ private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
138139
}
139140
}
140141
if (!matches.isEmpty()) {
141-
matches.sort(new ExceptionDepthComparator(exceptionType));
142+
if (matches.size() > 1) {
143+
matches.sort(new ExceptionDepthComparator(exceptionType));
144+
}
142145
return this.mappedMethods.get(matches.get(0));
143146
}
144147
else {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
* @author Rossen Stoyanchev
4141
* @author Juergen Hoeller
42+
* @author Sam Brannen
4243
* @since 3.1
4344
*/
4445
public class ExceptionHandlerMethodResolver {
@@ -179,7 +180,9 @@ private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
179180
}
180181
}
181182
if (!matches.isEmpty()) {
182-
matches.sort(new ExceptionDepthComparator(exceptionType));
183+
if (matches.size() > 1) {
184+
matches.sort(new ExceptionDepthComparator(exceptionType));
185+
}
183186
return this.mappedMethods.get(matches.get(0));
184187
}
185188
else {

0 commit comments

Comments
 (0)