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