Repository: netty/netty
File: common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java (Java)

Code before:
        addTask(ObjectUtil.checkNotNull(task, "task"));
        if (!inEventLoop()) {
            startThread();
        }
    }

    private void startThread() {
        if (started.compareAndSet(false, true)) {
            ClassLoader parentCCL = Thread.currentThread().getContextClassLoader();
            setContextClassLoader(Thread.currentThread(), null);
            try {
                final Thread t = threadFactory.newThread(taskRunner);
                // Set to null to ensure we not create classloader leaks by holds a strong reference to the inherited
                // classloader.
                // See:
                // - https://github.com/netty/netty/issues/7290
                // - https://bugs.openjdk.java.net/browse/JDK-7008595
                setContextClassLoader(t, null);

                // Set the thread before starting it as otherwise inEventLoop() may return false and so produce
                // an assert error.
                // See https://github.com/netty/netty/issues/4357
                thread = t;
                t.start();
            } finally {
                setContextClassLoader(Thread.currentThread(), parentCCL);
            }
        }
    }

    private static void setContextClassLoader(final Thread t, final ClassLoader cl) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                t.setContextClassLoader(cl);
                return null;
            }
        });
    }

    final class TaskRunner implements Runnable {
        @Override
        public void run() {
            for (;;) {
                Runnable task = takeTask();
                if (task != null) {
                    try {
                        runTask(task);
                    } catch (Throwable t) {
                        logger.warn("Unexpected exception from the global event executor: ", t);
                    }

Review comment (suggestion):
```suggestion
                setContextClassLoader(current, parentCCL);
```

Code after:
        addTask(ObjectUtil.checkNotNull(task, "task"));
        if (!inEventLoop()) {
            startThread();
        }
    }

    private void startThread() {
        if (started.compareAndSet(false, true)) {
            Thread callingThread = Thread.currentThread();
            ClassLoader parentCCL = callingThread.getContextClassLoader();
            // Avoid calling classloader leaking through Thread.inheritedAccessControlContext.
            setContextClassLoader(callingThread, null);
            try {
                final Thread t = threadFactory.newThread(taskRunner);
                // Set to null to ensure we not create classloader leaks by holds a strong reference to the inherited
                // classloader.
                // See:
                // - https://github.com/netty/netty/issues/7290
                // - https://bugs.openjdk.java.net/browse/JDK-7008595
                setContextClassLoader(t, null);

                // Set the thread before starting it as otherwise inEventLoop() may return false and so produce
                // an assert error.
                // See https://github.com/netty/netty/issues/4357
                thread = t;
                t.start();
            } finally {
                setContextClassLoader(callingThread, parentCCL);
            }
        }
    }

    private static void setContextClassLoader(final Thread t, final ClassLoader cl) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                t.setContextClassLoader(cl);
                return null;
            }
        });
    }

    final class TaskRunner implements Runnable {
        @Override
        public void run() {
            for (;;) {
                Runnable task = takeTask();
                if (task != null) {
                    try {
                        runTask(task);
                    } catch (Throwable t) {