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 2173824c828f..045dae56bb0d 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 @@ -108,7 +108,9 @@ public Method resolveMethodByExceptionType(Class exceptionT Method method = this.exceptionLookupCache.get(exceptionType); if (method == null) { method = getMappedMethod(exceptionType); - this.exceptionLookupCache.put(exceptionType, method); + if (method != null) { + this.exceptionLookupCache.put(exceptionType, method); + } } return method; } 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 5fc02bd9ed8e..f5f0d9eab735 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 @@ -151,7 +151,9 @@ public Method resolveMethodByExceptionType(Class exceptionT Method method = this.exceptionLookupCache.get(exceptionType); if (method == null) { method = getMappedMethod(exceptionType); - this.exceptionLookupCache.put(exceptionType, method); + if (method != null) { + this.exceptionLookupCache.put(exceptionType, method); + } } return method; }