mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-28 18:19:05 +00:00
Fix issue in AnnotationMethodHandlerExceptionResolver
Caching of resovled exceptions introduced in SPR-7703 also introduced a side effect whereby if exactly one exception was previously cached, any other exception would appear as a match to the previously matched @ExceptionHandler method. This change ensures use of a fresh map when determining matching @ExceptionHandler methods while also updating the cache. Issue: SPR-9209
This commit is contained in:
+17
-2
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -110,7 +111,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
|
||||
assertEquals("Invalid view name returned", "GenericError", mav.getViewName());
|
||||
assertEquals("Invalid status code returned", 500, response.getStatus());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void ambiguous() {
|
||||
IllegalArgumentException ex = new IllegalArgumentException();
|
||||
@@ -127,7 +128,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
|
||||
assertTrue("ModelAndView not empty", mav.isEmpty());
|
||||
assertEquals("Invalid response written", "IllegalArgumentException", response.getContentAsString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void responseBody() throws UnsupportedEncodingException {
|
||||
IllegalArgumentException ex = new IllegalArgumentException();
|
||||
@@ -139,6 +140,20 @@ public class AnnotationMethodHandlerExceptionResolverTests {
|
||||
assertEquals("Invalid response written", "IllegalArgumentException", response.getContentAsString());
|
||||
}
|
||||
|
||||
// SPR-9209
|
||||
|
||||
@Test
|
||||
public void cachingSideEffect() {
|
||||
IllegalArgumentException ex = new IllegalArgumentException();
|
||||
SimpleController controller = new SimpleController();
|
||||
|
||||
ModelAndView mav = exceptionResolver.resolveException(request, response, controller, ex);
|
||||
assertNotNull("No ModelAndView returned", mav);
|
||||
|
||||
mav = exceptionResolver.resolveException(request, response, controller, new NullPointerException());
|
||||
assertNull(mav);
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
private static class SimpleController {
|
||||
|
||||
Reference in New Issue
Block a user