diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java index e69fe2fdb4..977d4f05f8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -359,7 +359,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce if (logger.isDebugEnabled()) { logger.debug("Invoking @ExceptionHandler method: " + exceptionHandlerMethod); } - exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception); + exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, handlerMethod); } catch (Exception invocationEx) { if (logger.isErrorEnabled()) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java index 7de8773bf6..74a028b326 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -201,6 +201,23 @@ public class ExceptionHandlerExceptionResolverTests { assertEquals("TestExceptionResolver: IllegalStateException", this.response.getContentAsString()); } + // SPR-12605 + + @Test + public void resolveExceptionWithHandlerMethodArg() throws Exception { + AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyConfig.class); + this.resolver.setApplicationContext(cxt); + this.resolver.afterPropertiesSet(); + + ArrayIndexOutOfBoundsException ex = new ArrayIndexOutOfBoundsException(); + HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle"); + ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex); + + assertNotNull("Exception was not handled", mav); + assertTrue(mav.isEmpty()); + assertEquals("HandlerMethod: handle", this.response.getContentAsString()); + } + @Test public void resolveExceptionControllerAdviceHandler() throws Exception { AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyControllerAdviceConfig.class); @@ -289,6 +306,12 @@ public class ExceptionHandlerExceptionResolverTests { public String handleException(IllegalStateException ex) { return "TestExceptionResolver: " + ClassUtils.getShortName(ex.getClass()); } + + @ExceptionHandler(ArrayIndexOutOfBoundsException.class) + @ResponseBody + public String handleWithHandlerMethod(HandlerMethod handlerMethod) { + return "HandlerMethod: " + handlerMethod.getMethod().getName(); + } } @ControllerAdvice