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 the shared TransferEncodingNotAllowedExcep… · netty/netty@742a53e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-base/src/main/java/io/netty/handler/codec
    • CodecException.java
    • DecoderException.java
  • codec-http/src
    • main/java/io/netty/handler/codec/http
      • HttpObjectDecoder.java
      • TransferEncodingNotAllowedException.java
    • test/java/io/netty/handler/codec/http
      • HttpRequestDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-base/src/main/java/io/netty/handler/codec/CodecException.java‎

Copy file name to clipboardExpand all lines: codec-base/src/main/java/io/netty/handler/codec/CodecException.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ public CodecException(String message) {
4848
public CodecException(Throwable cause) {
4949
super(cause);
5050
}
51+
52+
/**
53+
* Creates a new instance with the given suppression and stack trace settings, see
54+
* {@link RuntimeException#RuntimeException(String, Throwable, boolean, boolean)}.
55+
*/
56+
protected CodecException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
57+
super(message, cause, enableSuppression, writableStackTrace);
58+
}
5159
}
Collapse file

‎codec-base/src/main/java/io/netty/handler/codec/DecoderException.java‎

Copy file name to clipboardExpand all lines: codec-base/src/main/java/io/netty/handler/codec/DecoderException.java
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ public DecoderException(String message) {
4848
public DecoderException(Throwable cause) {
4949
super(cause);
5050
}
51+
52+
/**
53+
* Creates a new instance with the given suppression and stack trace settings, see
54+
* {@link RuntimeException#RuntimeException(String, Throwable, boolean, boolean)}.
55+
*/
56+
protected DecoderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
57+
super(message, cause, enableSuppression, writableStackTrace);
58+
}
5159
}
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import io.netty.util.ByteProcessor;
2828
import io.netty.util.internal.StringUtil;
2929
import io.netty.util.internal.SystemPropertyUtil;
30-
import io.netty.util.internal.ThrowableUtil;
3130

3231
import java.util.List;
3332
import java.util.concurrent.atomic.AtomicBoolean;
@@ -173,11 +172,8 @@ public void run() {
173172
}
174173
};
175174
private static final TransferEncodingNotAllowedException TRANSFER_ENCODING_NOT_ALLOWED =
176-
ThrowableUtil.unknownStackTrace(
177-
new TransferEncodingNotAllowedException(
178-
"The Transfer-Encoding header is only allowed in HTTP/1.1 or newer"),
179-
HttpObjectDecoder.class,
180-
"readHeaders(ByteBuf)");
175+
TransferEncodingNotAllowedException.newStatic(
176+
"The Transfer-Encoding header is only allowed in HTTP/1.1 or newer");
181177

182178
private final int maxChunkSize;
183179
private final boolean chunkedSupported;
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/TransferEncodingNotAllowedException.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/TransferEncodingNotAllowedException.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@ public final class TransferEncodingNotAllowedException extends DecoderException
2929
public TransferEncodingNotAllowedException(String message) {
3030
super(message);
3131
}
32+
33+
private TransferEncodingNotAllowedException(String message, boolean shared) {
34+
// A shared instance must not populate a (native) backtrace: doing so would pin the Classloader of whatever
35+
// thread happened to trigger its creation (see https://github.com/netty/netty/issues/17128).
36+
super(message, null, false, false);
37+
assert shared;
38+
}
39+
40+
static TransferEncodingNotAllowedException newStatic(String message) {
41+
return new TransferEncodingNotAllowedException(message, true);
42+
}
3243
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static io.netty.handler.codec.http.HttpHeaderNames.HOST;
3737
import static io.netty.handler.codec.http.HttpHeadersTestUtils.of;
3838
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3940
import static org.junit.jupiter.api.Assertions.assertEquals;
4041
import static org.junit.jupiter.api.Assertions.assertFalse;
4142
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -863,6 +864,26 @@ public void testContentLengthHeaderAndChunkedHttp10() {
863864
assertFalse(channel.finish());
864865
}
865866

867+
@Test
868+
public void testTransferEncodingNotAllowedDoesNotFillInStackTrace() {
869+
String requestStr = "POST / HTTP/1.0\r\n" +
870+
"Host: example.com\r\n" +
871+
"Transfer-Encoding: chunked\r\n\r\n" +
872+
"0\r\n\r\n";
873+
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
874+
assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII)));
875+
HttpRequest request = channel.readInbound();
876+
Throwable cause = request.decoderResult().cause();
877+
assertInstanceOf(TransferEncodingNotAllowedException.class, cause);
878+
879+
// The exception is shared, so it must not populate a (native) backtrace: doing so would pin the Classloader
880+
// of whatever thread happened to trigger its creation (see https://github.com/netty/netty/issues/17128).
881+
StackTraceElement[] before = cause.getStackTrace();
882+
cause.fillInStackTrace();
883+
assertArrayEquals(before, cause.getStackTrace());
884+
assertFalse(channel.finish());
885+
}
886+
866887
@Test
867888
void mustRejectImproperlyTerminatedChunkExtensions() throws Exception {
868889
// See full explanation: https://w4ke.info/2025/06/18/funky-chunks.html

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.