diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java index 60f9d1c0e3..58bbe60cfd 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java @@ -19,6 +19,7 @@ package org.springframework.messaging.handler.invocation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,7 +39,7 @@ import org.springframework.util.ConcurrentReferenceHashMap; */ public abstract class AbstractExceptionHandlerMethodResolver { - private final Map, Method> mappedMethods = new ConcurrentReferenceHashMap<>(16); + private final Map, Method> mappedMethods = new HashMap<>(16); private final Map, Method> exceptionLookupCache = new ConcurrentReferenceHashMap<>(16); @@ -64,7 +65,9 @@ public abstract class AbstractExceptionHandlerMethodResolver { result.add((Class) paramType); } } - Assert.notEmpty(result, "No exception types mapped to {" + method + "}"); + if (result.isEmpty()) { + throw new IllegalStateException("No exception types mapped to " + method); + } return result; } @@ -73,7 +76,7 @@ public abstract class AbstractExceptionHandlerMethodResolver { * Whether the contained type has any exception mappings. */ public boolean hasExceptionMappings() { - return (this.mappedMethods.size() > 0); + return !this.mappedMethods.isEmpty(); } /** diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolverTests.java index 2966a290c6..e28577c875 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,7 +94,7 @@ public class AnnotationExceptionHandlerMethodResolverTests { new AnnotationExceptionHandlerMethodResolver(AmbiguousController.class); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void noExceptionMapping() { new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java index f54f2619d6..692fc9722e 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,7 +51,7 @@ public class ExceptionHandlerMethodResolver { (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null); - private final Map, Method> mappedMethods = new ConcurrentReferenceHashMap<>(16); + private final Map, Method> mappedMethods = new HashMap<>(16); private final Map, Method> exceptionLookupCache = new ConcurrentReferenceHashMap<>(16); @@ -83,7 +84,9 @@ public class ExceptionHandlerMethodResolver { } } } - Assert.notEmpty(result, "No exception types mapped to {" + method + "}"); + if (result.isEmpty()) { + throw new IllegalStateException("No exception types mapped to " + method); + } return result; } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java index 999178f6fa..98032176eb 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,11 +88,12 @@ public class ExceptionHandlerMethodResolverTests { new ExceptionHandlerMethodResolver(AmbiguousController.class); } - @Test(expected = IllegalArgumentException.class) + @Test(expected = IllegalStateException.class) public void noExceptionMapping() { new ExceptionHandlerMethodResolver(NoExceptionController.class); } + @Controller static class ExceptionController { @@ -111,6 +112,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class InheritedController extends ExceptionController { @@ -119,6 +121,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class AmbiguousController { @@ -136,6 +139,7 @@ public class ExceptionHandlerMethodResolverTests { } } + @Controller static class NoExceptionController {