|  | 
| 47 | 47 |  */ | 
| 48 | 48 | public class InvocableHandlerMethod extends HandlerMethod { | 
| 49 | 49 | 
 | 
| 50 |  | -	private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); | 
| 51 |  | - | 
| 52 | 50 | 	private WebDataBinderFactory dataBinderFactory; | 
| 53 | 51 | 
 | 
|  | 52 | +	private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); | 
|  | 53 | + | 
| 54 | 54 | 	private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); | 
| 55 | 55 | 
 | 
| 56 | 56 | 
 | 
| 57 | 57 | 	/** | 
| 58 |  | -	 * Creates an instance from the given handler and method. | 
|  | 58 | +	 * Create an instance from the given handler and method. | 
| 59 | 59 | 	 */ | 
| 60 | 60 | 	public InvocableHandlerMethod(Object bean, Method method) { | 
| 61 | 61 | 		super(bean, method); | 
| @@ -124,7 +124,7 @@ public final Object invokeForRequest(NativeWebRequest request, ModelAndViewConta | 
| 124 | 124 | 		Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs); | 
| 125 | 125 | 		if (logger.isTraceEnabled()) { | 
| 126 | 126 | 			StringBuilder sb = new StringBuilder("Invoking ["); | 
| 127 |  | -			sb.append(this.getBeanType().getSimpleName()).append("."); | 
|  | 127 | +			sb.append(getBeanType().getSimpleName()).append("."); | 
| 128 | 128 | 			sb.append(getMethod().getName()).append("] method with arguments "); | 
| 129 | 129 | 			sb.append(Arrays.asList(args)); | 
| 130 | 130 | 			logger.trace(sb.toString()); | 
| @@ -154,7 +154,8 @@ private Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewC | 
| 154 | 154 | 			} | 
| 155 | 155 | 			if (this.argumentResolvers.supportsParameter(parameter)) { | 
| 156 | 156 | 				try { | 
| 157 |  | -					args[i] = this.argumentResolvers.resolveArgument(parameter, mavContainer, request, this.dataBinderFactory); | 
|  | 157 | +					args[i] = this.argumentResolvers.resolveArgument( | 
|  | 158 | +							parameter, mavContainer, request, this.dataBinderFactory); | 
| 158 | 159 | 					continue; | 
| 159 | 160 | 				} | 
| 160 | 161 | 				catch (Exception ex) { | 
| @@ -209,17 +210,17 @@ private Object resolveProvidedArgument(MethodParameter parameter, Object... prov | 
| 209 | 210 | 	 * Invoke the handler method with the given argument values. | 
| 210 | 211 | 	 */ | 
| 211 | 212 | 	private Object invoke(Object... args) throws Exception { | 
| 212 |  | -		ReflectionUtils.makeAccessible(this.getBridgedMethod()); | 
|  | 213 | +		ReflectionUtils.makeAccessible(getBridgedMethod()); | 
| 213 | 214 | 		try { | 
| 214 |  | -			assertTargetBean(getBridgedMethod(), getBean(), args); | 
| 215 | 215 | 			return getBridgedMethod().invoke(getBean(), args); | 
| 216 | 216 | 		} | 
| 217 |  | -		catch (IllegalArgumentException e) { | 
| 218 |  | -			throw new IllegalArgumentException(getInvocationErrorMessage(e.getMessage(), args), e); | 
|  | 217 | +		catch (IllegalArgumentException ex) { | 
|  | 218 | +			assertTargetBean(getBridgedMethod(), getBean(), args); | 
|  | 219 | +			throw new IllegalStateException(getInvocationErrorMessage(ex.getMessage(), args), ex); | 
| 219 | 220 | 		} | 
| 220 |  | -		catch (InvocationTargetException e) { | 
|  | 221 | +		catch (InvocationTargetException ex) { | 
| 221 | 222 | 			// Unwrap for HandlerExceptionResolvers ... | 
| 222 |  | -			Throwable targetException = e.getTargetException(); | 
|  | 223 | +			Throwable targetException = ex.getTargetException(); | 
| 223 | 224 | 			if (targetException instanceof RuntimeException) { | 
| 224 | 225 | 				throw (RuntimeException) targetException; | 
| 225 | 226 | 			} | 
| @@ -247,11 +248,11 @@ private void assertTargetBean(Method method, Object targetBean, Object[] args) { | 
| 247 | 248 | 		Class<?> methodDeclaringClass = method.getDeclaringClass(); | 
| 248 | 249 | 		Class<?> targetBeanClass = targetBean.getClass(); | 
| 249 | 250 | 		if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) { | 
| 250 |  | -			String message = "The mapped controller method class '" + methodDeclaringClass.getName() + | 
|  | 251 | +			String msg = "The mapped controller method class '" + methodDeclaringClass.getName() + | 
| 251 | 252 | 					"' is not an instance of the actual controller bean instance '" + | 
| 252 | 253 | 					targetBeanClass.getName() + "'. If the controller requires proxying " + | 
| 253 | 254 | 					"(e.g. due to @Transactional), please use class-based proxying."; | 
| 254 |  | -			throw new IllegalArgumentException(getInvocationErrorMessage(message, args)); | 
|  | 255 | +			throw new IllegalStateException(getInvocationErrorMessage(msg, args)); | 
| 255 | 256 | 		} | 
| 256 | 257 | 	} | 
| 257 | 258 | 
 | 
|  | 
0 commit comments