Skip to content

Commit

Permalink
Issue #5859 Ensure inheritedAccessContext doesn't pin classloader
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Jan 20, 2021
1 parent 399db82 commit 7f270a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Expand Up @@ -20,6 +20,8 @@

import java.io.Closeable;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -685,12 +687,19 @@ private boolean addCounts(int deltaThreads, int deltaIdle)
@Override
public Thread newThread(Runnable runnable)
{
Thread thread = new Thread(_threadGroup, runnable);
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
thread.setContextClassLoader(this.getClass().getClassLoader());
return thread;
return (AccessController.doPrivileged(new PrivilegedAction<Thread>()
{
@Override
public Thread run()
{
Thread thread = new Thread(_threadGroup, runnable);
thread.setDaemon(isDaemon());
thread.setPriority(getThreadsPriority());
thread.setName(_name + "-" + thread.getId());
thread.setContextClassLoader(this.getClass().getClassLoader());
return thread;
}
}));
}

protected void removeThread(Thread thread)
Expand Down
Expand Up @@ -18,6 +18,8 @@

package org.eclipse.jetty.util.thread;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
Expand All @@ -36,7 +38,15 @@
public class ShutdownThread extends Thread
{
private static final Logger LOG = Log.getLogger(ShutdownThread.class);
private static final ShutdownThread _thread = new ShutdownThread();
private static final ShutdownThread _thread = AccessController.doPrivileged(new PrivilegedAction<ShutdownThread>()
{
@Override
public ShutdownThread run()
{
return new ShutdownThread();
}

});

private boolean _hooked;
private final List<LifeCycle> _lifeCycles = new CopyOnWriteArrayList<LifeCycle>();
Expand Down

0 comments on commit 7f270a0

Please sign in to comment.