diff --git a/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/RequestDispatcher.java b/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/RequestDispatcher.java index 9af166908ef7f..7662ce0f904a6 100644 --- a/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/RequestDispatcher.java +++ b/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/RequestDispatcher.java @@ -58,11 +58,13 @@ public void service(Context context, HttpRequest vertxReq, HttpResponse vertxResp, boolean handleNotFound, Throwable throwable) throws IOException { ClassLoader old = Thread.currentThread().getContextClassLoader(); + boolean providerFactoryPushedToThreadLocal = false; try { Thread.currentThread().setContextClassLoader(classLoader); ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance(); if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) { ThreadLocalResteasyProviderFactory.push(providerFactory); + providerFactoryPushedToThreadLocal = true; } try { @@ -88,8 +90,7 @@ public void accept(Throwable throwable) { } } finally { try { - ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance(); - if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) { + if (providerFactoryPushedToThreadLocal) { ThreadLocalResteasyProviderFactory.pop(); } } finally {