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:
Rossen Stoyanchev
2012-10-06 21:52:21 -04:00
parent 3eda02d1b4
commit 3552173b81
4 changed files with 47 additions and 14 deletions

View File

@@ -110,7 +110,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 +127,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 +139,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 {