From c7d6a98de29c783d309729012adb8f071319aecd Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 1 Nov 2021 10:54:43 +0200 Subject: [PATCH 1/2] Always preserve target when an exception is thrown Relates to: #21120 --- .../reactive/common/core/AbstractResteasyReactiveContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java index 1b08a3ec8c7f1..adb8f41f9536d 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java @@ -161,7 +161,7 @@ public void run() { if (t instanceof PreserveTargetException) { handleException(t.getCause(), true); } else { - handleException(t); + handleException(t, true); } if (aborted) { return; From 6cd9b08cdf4e5f4889bd7840670af2413ea513a0 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 1 Nov 2021 10:59:13 +0200 Subject: [PATCH 2/2] Guard against RuntimeResource being null in ExceptionMapping Relates to: #21120 --- .../server/core/ExceptionMapping.java | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ExceptionMapping.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ExceptionMapping.java index f1d0d44ea47d6..db68bf80bc701 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ExceptionMapping.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ExceptionMapping.java @@ -22,6 +22,7 @@ import org.jboss.logging.Logger; import org.jboss.resteasy.reactive.ResteasyReactiveClientProblem; import org.jboss.resteasy.reactive.common.model.ResourceExceptionMapper; +import org.jboss.resteasy.reactive.server.mapping.RuntimeResource; import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveAsyncExceptionMapper; import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveExceptionMapper; import org.jboss.resteasy.reactive.spi.BeanFactory; @@ -99,31 +100,46 @@ public void mapException(Throwable throwable, ResteasyReactiveRequestContext con private void logBlockingErrorIfRequired(Throwable throwable, ResteasyReactiveRequestContext context) { if (isBlockingProblem(throwable)) { - log.error("A blocking operation occurred on the IO thread. This likely means you need to annotate " - + context.getTarget().getResourceClass().getName() + "#" + context.getTarget().getJavaMethodName() + "(" - + Arrays.stream(context.getTarget().getParameterTypes()).map(Objects::toString) - .collect(Collectors.joining(", ")) - + ") with @" - + Blocking.class.getName() - + ". Alternatively you can annotate the class " + context.getTarget().getResourceClass().getName() - + " to make every method on the class blocking, or annotate your sub class of the " - + Application.class.getName() + " class to make the whole application blocking"); + RuntimeResource runtimeResource = context.getTarget(); + if (runtimeResource == null) { + log.error("A blocking operation occurred on the IO thread. This likely means you need to use the @" + + Blocking.class.getName() + " annotation on the Resource method, class or " + + Application.class.getName() + " class."); + } else { + log.error("A blocking operation occurred on the IO thread. This likely means you need to annotate " + + runtimeResource.getResourceClass().getName() + "#" + runtimeResource.getJavaMethodName() + "(" + + Arrays.stream(runtimeResource.getParameterTypes()).map(Objects::toString) + .collect(Collectors.joining(", ")) + + ") with @" + + Blocking.class.getName() + + ". Alternatively you can annotate the class " + runtimeResource.getResourceClass().getName() + + " to make every method on the class blocking, or annotate your sub class of the " + + Application.class.getName() + " class to make the whole application blocking"); + } } } private void logNonBlockingErrorIfRequired(Throwable throwable, ResteasyReactiveRequestContext context) { if (isNonBlockingProblem(throwable)) { - log.error( - "An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you need to annotate " - + context.getTarget().getResourceClass().getName() + "#" + context.getTarget().getJavaMethodName() - + "(" - + Arrays.stream(context.getTarget().getParameterTypes()).map(Objects::toString) - .collect(Collectors.joining(", ")) - + ") with @" - + NonBlocking.class.getName() - + ". Alternatively you can annotate the class " + context.getTarget().getResourceClass().getName() - + " to make every method on the class run on a Vert.x EventLoop thread, or annotate your sub class of the " - + Application.class.getName() + " class to affect the entire application"); + RuntimeResource runtimeResource = context.getTarget(); + if (runtimeResource == null) { + log.error( + "An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you use the @" + + NonBlocking.class.getName() + " annotation on the Resource method, class or " + + Application.class.getName() + " class."); + } else { + log.error( + "An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you need to annotate " + + runtimeResource.getResourceClass().getName() + "#" + runtimeResource.getJavaMethodName() + + "(" + + Arrays.stream(runtimeResource.getParameterTypes()).map(Objects::toString) + .collect(Collectors.joining(", ")) + + ") with @" + + NonBlocking.class.getName() + + ". Alternatively you can annotate the class " + runtimeResource.getResourceClass().getName() + + " to make every method on the class run on a Vert.x EventLoop thread, or annotate your sub class of the " + + Application.class.getName() + " class to affect the entire application"); + } } }