Skip to content

Commit

Permalink
Avoid calling ResteasyProviderFactory.getInstance() when popping
Browse files Browse the repository at this point in the history
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 quarkusio#41233
  • Loading branch information
gsmet committed Jun 25, 2024
1 parent c38c488 commit 4fea558
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -88,8 +90,7 @@ public void accept(Throwable throwable) {
}
} finally {
try {
ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) {
if (providerFactoryPushedToThreadLocal) {
ThreadLocalResteasyProviderFactory.pop();
}
} finally {
Expand Down

0 comments on commit 4fea558

Please sign in to comment.