@@ -131,7 +131,7 @@ private TypedValue getValueInternal(EvaluationContext evaluationContext,
131
131
}
132
132
133
133
// either there was no accessor or it no longer existed
134
- executorToUse = findAccessorForMethod (this . name , argumentTypes , value , evaluationContext );
134
+ executorToUse = findAccessorForMethod (argumentTypes , value , evaluationContext );
135
135
this .cachedExecutor = new CachedMethodExecutor (
136
136
executorToUse , (value instanceof Class ? (Class <?>) value : null ), targetType , argumentTypes );
137
137
try {
@@ -196,33 +196,40 @@ private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Ob
196
196
return null ;
197
197
}
198
198
199
- private MethodExecutor findAccessorForMethod (String name , List <TypeDescriptor > argumentTypes ,
200
- Object targetObject , EvaluationContext evaluationContext ) throws SpelEvaluationException {
199
+ private MethodExecutor findAccessorForMethod (List <TypeDescriptor > argumentTypes , Object targetObject ,
200
+ EvaluationContext evaluationContext ) throws SpelEvaluationException {
201
201
202
+ AccessException accessException = null ;
202
203
List <MethodResolver > methodResolvers = evaluationContext .getMethodResolvers ();
203
204
for (MethodResolver methodResolver : methodResolvers ) {
204
205
try {
205
206
MethodExecutor methodExecutor = methodResolver .resolve (
206
- evaluationContext , targetObject , name , argumentTypes );
207
+ evaluationContext , targetObject , this . name , argumentTypes );
207
208
if (methodExecutor != null ) {
208
209
return methodExecutor ;
209
210
}
210
211
}
211
212
catch (AccessException ex ) {
212
- throw new SpelEvaluationException ( getStartPosition (), ex ,
213
- SpelMessage . PROBLEM_LOCATING_METHOD , name , targetObject . getClass ()) ;
213
+ accessException = ex ;
214
+ break ;
214
215
}
215
216
}
216
217
217
- throw new SpelEvaluationException (getStartPosition (), SpelMessage .METHOD_NOT_FOUND ,
218
- FormatHelper .formatMethodForMessage (name , argumentTypes ),
219
- FormatHelper .formatClassNameForMessage (
220
- targetObject instanceof Class ? ((Class <?>) targetObject ) : targetObject .getClass ()));
218
+ String method = FormatHelper .formatMethodForMessage (this .name , argumentTypes );
219
+ String className = FormatHelper .formatClassNameForMessage (
220
+ targetObject instanceof Class ? ((Class <?>) targetObject ) : targetObject .getClass ());
221
+ if (accessException != null ) {
222
+ throw new SpelEvaluationException (
223
+ getStartPosition (), accessException , SpelMessage .PROBLEM_LOCATING_METHOD , method , className );
224
+ }
225
+ else {
226
+ throw new SpelEvaluationException (getStartPosition (), SpelMessage .METHOD_NOT_FOUND , method , className );
227
+ }
221
228
}
222
229
223
230
/**
224
- * Decode the AccessException, throwing a lightweight evaluation exception or, if the
225
- * cause was a RuntimeException, throw the RuntimeException directly.
231
+ * Decode the AccessException, throwing a lightweight evaluation exception or,
232
+ * if the cause was a RuntimeException, throw the RuntimeException directly.
226
233
*/
227
234
private void throwSimpleExceptionIfPossible (Object value , AccessException ex ) {
228
235
if (ex .getCause () instanceof InvocationTargetException ) {
0 commit comments