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 22:03:31 -04:00
parent 470c85ade0
commit ec2603de63
4 changed files with 48 additions and 14 deletions

View File

@@ -16,17 +16,20 @@
package org.springframework.web.portlet.mvc.annotation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.BindException;
import java.net.SocketException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.portlet.MockRenderRequest;
import org.springframework.mock.web.portlet.MockRenderResponse;
import org.springframework.stereotype.Controller;
@@ -106,6 +109,20 @@ public class AnnotationMethodHandlerExceptionResolverTests {
exceptionResolver.resolveException(request, response, controller, ex);
}
// 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 {