diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index 23972879b5d..6758c6b1229 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -223,7 +223,8 @@ public class InvocableHandlerMethod extends HandlerMethod { } catch (IllegalArgumentException ex) { assertTargetBean(getBridgedMethod(), getBean(), args); - throw new IllegalStateException(getInvocationErrorMessage(ex.getMessage(), args), ex); + String message = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument"); + throw new IllegalStateException(getInvocationErrorMessage(message, args), ex); } catch (InvocationTargetException ex) { // Unwrap for HandlerExceptionResolvers ... diff --git a/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java b/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java index 4bd60cd5087..5dbe5486338 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -29,6 +29,7 @@ import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.*; /** @@ -195,6 +196,28 @@ public class InvocableHandlerMethodTests { } } + // SPR-13917 + + @Test + public void invocationErrorMessage() throws Exception { + HandlerMethodArgumentResolverComposite composite = new HandlerMethodArgumentResolverComposite(); + composite.addResolver(new StubArgumentResolver(double.class, null)); + + Method method = Handler.class.getDeclaredMethod("handle", double.class); + Object handler = new Handler(); + InvocableHandlerMethod hm = new InvocableHandlerMethod(handler, method); + hm.setHandlerMethodArgumentResolvers(composite); + + try { + hm.invokeForRequest(this.webRequest, new ModelAndViewContainer()); + fail(); + } + catch (IllegalStateException ex) { + assertThat(ex.getMessage(), containsString("Illegal argument")); + } + } + + private void invokeExceptionRaisingHandler(Throwable expected) throws Exception { Method method = ExceptionRaisingHandler.class.getDeclaredMethod("raiseException"); Object handler = new ExceptionRaisingHandler(expected); @@ -209,6 +232,9 @@ public class InvocableHandlerMethodTests { public String handle(Integer intArg, String stringArg) { return intArg + "-" + stringArg; } + + public void handle(double amount) { + } }