Browse Source

Avoid unnecessary sorting in base ExceptionHandlerMethodResolvers

pull/26385/head
Sam Brannen 4 years ago
parent
commit
570bdbd253
  1. 5
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java
  2. 5
      spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java

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

@ -34,6 +34,7 @@ import org.springframework.util.ConcurrentReferenceHashMap; @@ -34,6 +34,7 @@ import org.springframework.util.ConcurrentReferenceHashMap;
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sam Brannen
* @since 4.0
*/
public abstract class AbstractExceptionHandlerMethodResolver {
@ -138,7 +139,9 @@ public abstract class AbstractExceptionHandlerMethodResolver { @@ -138,7 +139,9 @@ public abstract class AbstractExceptionHandlerMethodResolver {
}
}
if (!matches.isEmpty()) {
matches.sort(new ExceptionDepthComparator(exceptionType));
if (matches.size() > 1) {
matches.sort(new ExceptionDepthComparator(exceptionType));
}
return this.mappedMethods.get(matches.get(0));
}
else {

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

@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; @@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.1
*/
public class ExceptionHandlerMethodResolver {
@ -179,7 +180,9 @@ public class ExceptionHandlerMethodResolver { @@ -179,7 +180,9 @@ public class ExceptionHandlerMethodResolver {
}
}
if (!matches.isEmpty()) {
matches.sort(new ExceptionDepthComparator(exceptionType));
if (matches.size() > 1) {
matches.sort(new ExceptionDepthComparator(exceptionType));
}
return this.mappedMethods.get(matches.get(0));
}
else {

Loading…
Cancel
Save