This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 2eccc64e48 Refactor hpackDecoder as a final field
2eccc64e48 is described below

commit 2eccc64e48f41b1983c5901800263e95b91a9ab3
Author: remm <[email protected]>
AuthorDate: Tue May 19 21:29:21 2026 +0200

    Refactor hpackDecoder as a final field
    
    It is almost always used and it's more robust.
---
 java/org/apache/coyote/http2/Http2Parser.java | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2Parser.java 
b/java/org/apache/coyote/http2/Http2Parser.java
index 11d30be04c..39d4ef310a 100644
--- a/java/org/apache/coyote/http2/Http2Parser.java
+++ b/java/org/apache/coyote/http2/Http2Parser.java
@@ -45,8 +45,8 @@ class Http2Parser {
     protected final Input input;
     private final Output output;
     private final byte[] frameHeaderBuffer = new byte[9];
+    private final HpackDecoder hpackDecoder;
 
-    private volatile HpackDecoder hpackDecoder;
     private volatile ByteBuffer headerReadBuffer = 
ByteBuffer.allocate(Constants.DEFAULT_HEADER_READ_BUFFER_SIZE);
     private volatile int headersCurrentStream = -1;
     private volatile boolean headersEndStream = false;
@@ -55,6 +55,7 @@ class Http2Parser {
         this.connectionId = connectionId;
         this.input = input;
         this.output = output;
+        this.hpackDecoder = output.getHpackDecoder();
     }
 
 
@@ -229,9 +230,6 @@ class Http2Parser {
 
         headersEndStream = Flags.isEndOfStream(flags);
 
-        if (hpackDecoder == null) {
-            hpackDecoder = output.getHpackDecoder();
-        }
         try {
             hpackDecoder.setHeaderEmitter(output.headersStart(streamId, 
headersEndStream));
         } catch (StreamException se) {
@@ -678,14 +676,8 @@ class Http2Parser {
         /*
          * Clear the reference to the stream in the HPack decoder now that the 
headers have been processed so that the
          * HPack decoder does not retain a reference to this stream. This aids 
GC.
-         *
-         * If the connection was created via an upgrade from HTTP/1.1 it is 
possible to reach this point before any
-         * HTTP/2 headers frames have been received which means hpackDecoder 
will still be null as lazy init is used.
          */
-        HpackDecoder hpackDecoder = this.hpackDecoder;
-        if (hpackDecoder != null) {
-            hpackDecoder.clearHeaderEmitter();
-        }
+        hpackDecoder.clearHeaderEmitter();
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to