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 — Auto-port 4.1: Avoid classloader leak via the shared TransferEncoding… · netty/netty@cbc3d67

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src
    • main/java/io/netty/handler/codec/http
      • HttpObjectDecoder.java
      • TransferEncodingNotAllowedException.java
    • test/java/io/netty/handler/codec/http
      • HttpRequestDecoderTest.java
  • codec/src/main/java/io/netty/handler/codec
    • CodecException.java
    • DecoderException.java
Expand file treeCollapse file tree
Open diff view settings
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
+3-6Lines changed: 3 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,9 @@ 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",
177+
HttpObjectDecoder.class, "readHeaders(ByteBuf)");
181178

182179
private final int maxChunkSize;
183180
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
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package io.netty.handler.codec.http;
1717

1818
import io.netty.handler.codec.DecoderException;
19+
import io.netty.util.internal.PlatformDependent;
20+
import io.netty.util.internal.SuppressJava6Requirement;
21+
import io.netty.util.internal.ThrowableUtil;
1922

2023
/**
2124
* Thrown by {@link HttpObjectDecoder} when an HTTP message uses a protocol version older than {@code HTTP/1.1}
@@ -29,4 +32,21 @@ public final class TransferEncodingNotAllowedException extends DecoderException
2932
public TransferEncodingNotAllowedException(String message) {
3033
super(message);
3134
}
35+
36+
@SuppressJava6Requirement(reason = "uses Java 7+ DecoderException.<init>(String, Throwable, boolean, boolean)" +
37+
" but is guarded by version checks")
38+
private TransferEncodingNotAllowedException(String message, boolean shared) {
39+
// A shared instance must not populate a (native) backtrace: doing so would pin the Classloader of whatever
40+
// thread happened to trigger its creation (see https://github.com/netty/netty/issues/17128).
41+
super(message, null, false, false);
42+
assert shared;
43+
}
44+
45+
static TransferEncodingNotAllowedException newStatic(String message, Class<?> clazz, String method) {
46+
if (PlatformDependent.javaVersion() >= 7) {
47+
return new TransferEncodingNotAllowedException(message, true);
48+
}
49+
// Java 6 has no way to disable the stack trace, so only replace the visible one.
50+
return ThrowableUtil.unknownStackTrace(new TransferEncodingNotAllowedException(message), clazz, method);
51+
}
3252
}
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
Collapse file

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

Copy file name to clipboardExpand all lines: codec/src/main/java/io/netty/handler/codec/CodecException.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.netty.handler.codec;
1717

18+
import io.netty.util.internal.SuppressJava6Requirement;
19+
1820
/**
1921
* An {@link Exception} which is thrown by a codec.
2022
*/
@@ -48,4 +50,17 @@ public CodecException(String message) {
4850
public CodecException(Throwable cause) {
4951
super(cause);
5052
}
53+
54+
/**
55+
* Creates a new instance with the given suppression and stack trace settings, see
56+
* {@link RuntimeException#RuntimeException(String, Throwable, boolean, boolean)}.
57+
* <p>
58+
* This constructor requires Java 7+ and must only be invoked after checking
59+
* {@code PlatformDependent.javaVersion() >= 7}.
60+
*/
61+
@SuppressJava6Requirement(reason = "uses Java 7+ RuntimeException.<init>(String, Throwable, boolean, boolean)" +
62+
" but callers are guarded by version checks")
63+
protected CodecException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
64+
super(message, cause, enableSuppression, writableStackTrace);
65+
}
5166
}
Collapse file

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

Copy file name to clipboardExpand all lines: codec/src/main/java/io/netty/handler/codec/DecoderException.java
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.netty.handler.codec;
1717

18+
import io.netty.util.internal.SuppressJava6Requirement;
19+
1820
/**
1921
* An {@link CodecException} which is thrown by a decoder.
2022
*/
@@ -48,4 +50,17 @@ public DecoderException(String message) {
4850
public DecoderException(Throwable cause) {
4951
super(cause);
5052
}
53+
54+
/**
55+
* Creates a new instance with the given suppression and stack trace settings, see
56+
* {@link RuntimeException#RuntimeException(String, Throwable, boolean, boolean)}.
57+
* <p>
58+
* This constructor requires Java 7+ and must only be invoked after checking
59+
* {@code PlatformDependent.javaVersion() >= 7}.
60+
*/
61+
@SuppressJava6Requirement(reason = "uses Java 7+ RuntimeException.<init>(String, Throwable, boolean, boolean)" +
62+
" but callers are guarded by version checks")
63+
protected DecoderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
64+
super(message, cause, enableSuppression, writableStackTrace);
65+
}
5166
}

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.