Skip to content

Commit 20931fc

Browse files
yoleintellij-monorepo-bot
authored andcommitted
Try to avoid capturing plugin classloaders via thread access control context (IDEA-239033)
GitOrigin-RevId: 0de3a19ec0bf8cb98096b36feefd042fae58a805
1 parent 978272e commit 20931fc

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

platform/util/src/com/intellij/execution/process/ProcessIOExecutorService.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.TestOnly;
66

7-
import java.util.concurrent.ExecutorService;
8-
import java.util.concurrent.SynchronousQueue;
9-
import java.util.concurrent.ThreadPoolExecutor;
10-
import java.util.concurrent.TimeUnit;
7+
import java.util.concurrent.*;
118

129
/**
1310
* A thread pool for long-running workers needed for handling child processes or network requests,
@@ -19,19 +16,26 @@ public class ProcessIOExecutorService extends ThreadPoolExecutor {
1916
public static final ExecutorService INSTANCE = new ProcessIOExecutorService();
2017

2118
private ProcessIOExecutorService() {
22-
super(1, Integer.MAX_VALUE, 1, TimeUnit.MINUTES, new SynchronousQueue<>(), new CountingThreadFactory() {
23-
@NotNull
24-
@Override
25-
public Thread newThread(@NotNull final Runnable r) {
26-
Thread thread = new Thread(r, POOLED_THREAD_PREFIX + counter.incrementAndGet());
27-
thread.setPriority(Thread.NORM_PRIORITY - 1);
28-
return thread;
29-
}
30-
});
19+
super(1, Integer.MAX_VALUE, 1, TimeUnit.MINUTES, new SynchronousQueue<>(), new MyCountingThreadFactory());
3120
}
3221

3322
@TestOnly
3423
public int getThreadCounter() {
3524
return ((CountingThreadFactory)getThreadFactory()).getCount();
3625
}
26+
27+
private static class MyCountingThreadFactory extends CountingThreadFactory {
28+
// Ensure that we don't keep the classloader of the plugin which caused this thread to be created
29+
// in Thread.inheritedAccessControlContext
30+
private final ThreadFactory myThreadFactory = Executors.privilegedThreadFactory();
31+
32+
@NotNull
33+
@Override
34+
public Thread newThread(@NotNull final Runnable r) {
35+
Thread thread = myThreadFactory.newThread(r);
36+
thread.setName(POOLED_THREAD_PREFIX + counter.incrementAndGet());
37+
thread.setPriority(Thread.NORM_PRIORITY - 1);
38+
return thread;
39+
}
40+
}
3741
}

platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ static ScheduledExecutorService getInstance() {
4040

4141
private static class MyThreadFactory extends CountingThreadFactory {
4242
private Consumer<? super Thread> newThreadListener;
43+
private final ThreadFactory myThreadFactory = Executors.privilegedThreadFactory();
4344

4445
@NotNull
4546
@Override
4647
public Thread newThread(@NotNull final Runnable r) {
47-
Thread thread = new Thread(r, POOLED_THREAD_PREFIX + counter.incrementAndGet());
48+
Thread thread = myThreadFactory.newThread(r);
49+
thread.setName(POOLED_THREAD_PREFIX + counter.incrementAndGet());
4850

4951
thread.setPriority(Thread.NORM_PRIORITY - 1);
5052

0 commit comments

Comments
 (0)