Skip to content

Commit

Permalink
Avoid unnecessary sorting in base ExceptionHandlerMethodResolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jan 11, 2021
1 parent b587a16 commit 570bdbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sam Brannen
* @since 4.0
*/
public abstract class AbstractExceptionHandlerMethodResolver {
Expand Down Expand Up @@ -138,7 +139,9 @@ private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
}
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.1
*/
public class ExceptionHandlerMethodResolver {
Expand Down Expand Up @@ -179,7 +180,9 @@ private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
}
}
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 {
Expand Down

0 comments on commit 570bdbd

Please sign in to comment.