@@ -176,46 +176,47 @@ public Mono<List<GraphQLError>> resolveException(
176
176
Throwable ex , DataFetchingEnvironment environment , @ Nullable Object controller ) {
177
177
178
178
Object controllerOrAdvice = null ;
179
- MethodHolder methodHolder = null ;
179
+ MethodReturnValueAdapter methodReturnValueAdapter = null ;
180
180
Class <?> controllerType = null ;
181
181
182
182
if (controller != null ) {
183
183
controllerType = ClassUtils .getUserClass (controller .getClass ());
184
184
MethodResolver methodResolver = this .controllerCache .get (controllerType );
185
185
if (methodResolver != null ) {
186
186
controllerOrAdvice = controller ;
187
- methodHolder = methodResolver .resolveMethod (ex );
187
+ methodReturnValueAdapter = methodResolver .resolveMethod (ex );
188
188
}
189
189
else if (logger .isWarnEnabled ()) {
190
190
logger .warn ("No registration for controller type: " + controllerType .getName ());
191
191
}
192
192
}
193
193
194
- if (methodHolder == null ) {
194
+ if (methodReturnValueAdapter == null ) {
195
195
for (Map .Entry <ControllerAdviceBean , MethodResolver > entry : this .controllerAdviceCache .entrySet ()) {
196
196
ControllerAdviceBean advice = entry .getKey ();
197
197
if (controller == null || advice .isApplicableToBeanType (controllerType )) {
198
- methodHolder = entry .getValue ().resolveMethod (ex );
199
- if (methodHolder != null ) {
198
+ methodReturnValueAdapter = entry .getValue ().resolveMethod (ex );
199
+ if (methodReturnValueAdapter != null ) {
200
200
controllerOrAdvice = advice .resolveBean ();
201
201
break ;
202
202
}
203
203
}
204
204
}
205
205
}
206
206
207
- if (methodHolder == null ) {
207
+ if (methodReturnValueAdapter == null ) {
208
208
return Mono .empty ();
209
209
}
210
210
211
- return invokeExceptionHandler (ex , environment , controllerOrAdvice , methodHolder );
211
+ return invokeExceptionHandler (ex , environment , controllerOrAdvice , methodReturnValueAdapter );
212
212
}
213
213
214
214
private Mono <List <GraphQLError >> invokeExceptionHandler (
215
- Throwable exception , DataFetchingEnvironment env , Object controllerOrAdvice , MethodHolder methodHolder ) {
215
+ Throwable exception , DataFetchingEnvironment env , Object controllerOrAdvice ,
216
+ MethodReturnValueAdapter methodReturnValueAdapter ) {
216
217
217
218
DataFetcherHandlerMethod exceptionHandler = new DataFetcherHandlerMethod (
218
- new HandlerMethod (controllerOrAdvice , methodHolder .getMethod ()), this .argumentResolvers ,
219
+ new HandlerMethod (controllerOrAdvice , methodReturnValueAdapter .getMethod ()), this .argumentResolvers ,
219
220
null , null , false , false );
220
221
221
222
List <Throwable > exceptions = new ArrayList <>();
@@ -237,7 +238,7 @@ private Mono<List<GraphQLError>> invokeExceptionHandler(
237
238
238
239
Object result = exceptionHandler .invoke (env , arguments );
239
240
240
- return methodHolder .adapt (result , exception );
241
+ return methodReturnValueAdapter .adapt (result , exception );
241
242
}
242
243
catch (Throwable invocationEx ) {
243
244
// Any other than the original exception (or a cause) is unintended here,
@@ -257,17 +258,17 @@ private Mono<List<GraphQLError>> invokeExceptionHandler(
257
258
private static final class MethodResolver {
258
259
259
260
@ SuppressWarnings ("DataFlowIssue" )
260
- private static final MethodHolder NO_MATCH =
261
- new MethodHolder (ReflectionUtils .findMethod (MethodResolver .class , "noMatch" ));
261
+ private static final MethodReturnValueAdapter NO_MATCH =
262
+ new MethodReturnValueAdapter (ReflectionUtils .findMethod (MethodResolver .class , "noMatch" ));
262
263
263
264
264
- private final Map <Class <? extends Throwable >, MethodHolder > exceptionMappings = new HashMap <>(16 );
265
+ private final Map <Class <? extends Throwable >, MethodReturnValueAdapter > exceptionMappings = new HashMap <>(16 );
265
266
266
- private final Map <Class <? extends Throwable >, MethodHolder > resolvedExceptionCache = new ConcurrentReferenceHashMap <>(16 );
267
+ private final Map <Class <? extends Throwable >, MethodReturnValueAdapter > resolvedExceptionCache = new ConcurrentReferenceHashMap <>(16 );
267
268
268
269
MethodResolver (Map <Class <? extends Throwable >, Method > methodMap ) {
269
270
methodMap .forEach ((exceptionType , method ) ->
270
- this .exceptionMappings .put (exceptionType , new MethodHolder (method )));
271
+ this .exceptionMappings .put (exceptionType , new MethodReturnValueAdapter (method )));
271
272
}
272
273
273
274
/**
@@ -277,8 +278,8 @@ private static final class MethodResolver {
277
278
* @return the exception handler to use, or {@code null} if no match
278
279
*/
279
280
@ Nullable
280
- MethodHolder resolveMethod (Throwable exception ) {
281
- MethodHolder method = resolveMethodByExceptionType (exception .getClass ());
281
+ MethodReturnValueAdapter resolveMethod (Throwable exception ) {
282
+ MethodReturnValueAdapter method = resolveMethodByExceptionType (exception .getClass ());
282
283
if (method == null ) {
283
284
Throwable cause = exception .getCause ();
284
285
if (cause != null ) {
@@ -289,16 +290,16 @@ MethodHolder resolveMethod(Throwable exception) {
289
290
}
290
291
291
292
@ Nullable
292
- private MethodHolder resolveMethodByExceptionType (Class <? extends Throwable > exceptionType ) {
293
- MethodHolder method = this .resolvedExceptionCache .get (exceptionType );
293
+ private MethodReturnValueAdapter resolveMethodByExceptionType (Class <? extends Throwable > exceptionType ) {
294
+ MethodReturnValueAdapter method = this .resolvedExceptionCache .get (exceptionType );
294
295
if (method == null ) {
295
296
method = getMappedMethod (exceptionType );
296
297
this .resolvedExceptionCache .put (exceptionType , method );
297
298
}
298
299
return (method != NO_MATCH ) ? method : null ;
299
300
}
300
301
301
- private MethodHolder getMappedMethod (Class <? extends Throwable > exceptionType ) {
302
+ private MethodReturnValueAdapter getMappedMethod (Class <? extends Throwable > exceptionType ) {
302
303
List <Class <? extends Throwable >> matches = new ArrayList <>();
303
304
for (Class <? extends Throwable > mappedException : this .exceptionMappings .keySet ()) {
304
305
if (mappedException .isAssignableFrom (exceptionType )) {
@@ -324,17 +325,17 @@ private void noMatch() {
324
325
325
326
326
327
/**
327
- * Container for an exception handler method, and an adapter for its return values .
328
+ * Helps to adapt the return value of an exception handler method .
328
329
*/
329
- private static class MethodHolder {
330
+ private static class MethodReturnValueAdapter {
330
331
331
332
private final Method method ;
332
333
333
334
private final MethodParameter returnType ;
334
335
335
336
private final ReturnValueAdapter adapter ;
336
337
337
- MethodHolder (Method method ) {
338
+ MethodReturnValueAdapter (Method method ) {
338
339
Assert .notNull (method , "Method is required" );
339
340
this .method = method ;
340
341
this .returnType = new MethodParameter (method , -1 );
0 commit comments