GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Avoid classloader leak via ImmediateEventExecutor terminationFuture f… · netty/netty@faa14e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common/src
    • main/java/io/netty/util/concurrent
      • GlobalEventExecutor.java
      • ImmediateEventExecutor.java
      • StacklessUnsupportedOperationException.java
    • test/java/io/netty/util/concurrent
      • ImmediateEventExecutorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java‎

Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java
-21Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import io.netty.util.internal.ObjectUtil;
1919
import io.netty.util.internal.SystemPropertyUtil;
2020
import io.netty.util.internal.ThreadExecutorMap;
21-
import io.netty.util.internal.ThrowableUtil;
2221
import io.netty.util.internal.logging.InternalLogger;
2322
import io.netty.util.internal.logging.InternalLoggerFactory;
2423

@@ -326,24 +325,4 @@ public void run() {
326325
}
327326
}
328327
}
329-
330-
private static final class StacklessUnsupportedOperationException extends UnsupportedOperationException {
331-
332-
private static final long serialVersionUID = -8060232216137960173L;
333-
334-
private StacklessUnsupportedOperationException() { }
335-
336-
// Override fillInStackTrace() so we not populate the backtrace via a native call and so leak the
337-
// Classloader. As the GlobalEventExecutor.INSTANCE is a singleton and holds on to this exception via its
338-
// terminationFuture, a populated backtrace would pin the Classloader of whatever thread happened to trigger
339-
// the lazy initialization of INSTANCE (see https://github.com/netty/netty/issues/17128).
340-
@Override
341-
public Throwable fillInStackTrace() {
342-
return this;
343-
}
344-
345-
static StacklessUnsupportedOperationException newInstance(Class<?> clazz, String method) {
346-
return ThrowableUtil.unknownStackTrace(new StacklessUnsupportedOperationException(), clazz, method);
347-
}
348-
}
349328
}
Collapse file

‎common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java‎

Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/concurrent/ImmediateEventExecutor.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ protected Boolean initialValue() throws Exception {
5252
}
5353
};
5454

55-
private final Future<?> terminationFuture = new FailedFuture<Object>(
56-
GlobalEventExecutor.INSTANCE, new UnsupportedOperationException());
55+
private final Future<?> terminationFuture = new FailedFuture<Object>(GlobalEventExecutor.INSTANCE,
56+
StacklessUnsupportedOperationException.newInstance(ImmediateEventExecutor.class, "terminationFuture"));
5757

5858
private ImmediateEventExecutor() { }
5959

Collapse file

‎common/src/main/java/io/netty/util/concurrent/StacklessUnsupportedOperationException.java‎

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.util.concurrent;
17+
18+
import io.netty.util.internal.ThrowableUtil;
19+
20+
/**
21+
* The failure of the {@link EventExecutor#terminationFuture()} of executors that can't be terminated, such as
22+
* {@link GlobalEventExecutor} and {@link ImmediateEventExecutor}.
23+
*/
24+
final class StacklessUnsupportedOperationException extends UnsupportedOperationException {
25+
26+
private static final long serialVersionUID = -8060232216137960173L;
27+
28+
private StacklessUnsupportedOperationException() { }
29+
30+
// Override fillInStackTrace() so we not populate the backtrace via a native call and so leak the
31+
// Classloader. The executors are singletons that hold on to this exception via their terminationFuture, so a
32+
// populated backtrace would pin the Classloader of whatever thread happened to trigger the lazy initialization
33+
// of their INSTANCE (see https://github.com/netty/netty/issues/17128).
34+
@Override
35+
public Throwable fillInStackTrace() {
36+
return this;
37+
}
38+
39+
static StacklessUnsupportedOperationException newInstance(Class<?> clazz, String method) {
40+
return ThrowableUtil.unknownStackTrace(new StacklessUnsupportedOperationException(), clazz, method);
41+
}
42+
}
Collapse file

‎common/src/test/java/io/netty/util/concurrent/ImmediateEventExecutorTest.java‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.util.concurrent;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
23+
24+
public class ImmediateEventExecutorTest {
25+
26+
@Test
27+
public void testTerminationFutureFailureDoesNotFillInStackTrace() {
28+
// ImmediateEventExecutor.INSTANCE is a singleton that holds on to the failure of its terminationFuture for
29+
// the lifetime of its Classloader, so that failure must not populate a (native) backtrace: doing so would
30+
// pin the Classloader of whatever thread happened to trigger the lazy initialization of INSTANCE
31+
// (see https://github.com/netty/netty/issues/17128).
32+
Throwable cause = ImmediateEventExecutor.INSTANCE.terminationFuture().cause();
33+
assertInstanceOf(UnsupportedOperationException.class, cause);
34+
35+
StackTraceElement[] before = cause.getStackTrace();
36+
assertEquals(1, before.length);
37+
assertEquals(ImmediateEventExecutor.class.getName(), before[0].getClassName());
38+
assertEquals("terminationFuture", before[0].getMethodName());
39+
40+
// fillInStackTrace() must be a no-op; otherwise it would repopulate the backtrace with native frames.
41+
cause.fillInStackTrace();
42+
assertArrayEquals(before, cause.getStackTrace());
43+
}
44+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.