From 4fea558e2886608effb5f031db6f46ea7daef1a7 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 17 Jun 2024 14:41:47 +0200 Subject: [PATCH] Avoid calling ResteasyProviderFactory.getInstance() when popping When popping provider factory, what we actually want is pop it if something has been pushed. It is better handled by setting a boolean if something has been pushed. This allows class loading issues when the class loader has been closed and the request is still processing. Related to #41233 --- .../resteasy/runtime/standalone/RequestDispatcher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 {