Strong references to mapped exception handler methods
Issue: SPR-15907
This commit is contained in:
parent
b122bc6dcc
commit
2b44e6e21c
|
|
@ -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<Class<? extends Throwable>, Method> mappedMethods = new ConcurrentReferenceHashMap<>(16);
|
||||
private final Map<Class<? extends Throwable>, Method> mappedMethods = new HashMap<>(16);
|
||||
|
||||
private final Map<Class<? extends Throwable>, Method> exceptionLookupCache = new ConcurrentReferenceHashMap<>(16);
|
||||
|
||||
|
|
@ -64,7 +65,9 @@ public abstract class AbstractExceptionHandlerMethodResolver {
|
|||
result.add((Class<? extends Throwable>) 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Class<? extends Throwable>, Method> mappedMethods = new ConcurrentReferenceHashMap<>(16);
|
||||
private final Map<Class<? extends Throwable>, Method> mappedMethods = new HashMap<>(16);
|
||||
|
||||
private final Map<Class<? extends Throwable>, 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue