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

markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/11.0.x by this push:
     new e94981ab7e Refactor to reduce code duplication
e94981ab7e is described below

commit e94981ab7e8ea4574f4e02393f0cb15045cb0017
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Apr 1 17:45:47 2026 +0100

    Refactor to reduce code duplication
---
 java/org/apache/coyote/http2/HpackDecoder.java | 17 ++++-------------
 webapps/docs/changelog.xml                     |  4 ++++
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/java/org/apache/coyote/http2/HpackDecoder.java 
b/java/org/apache/coyote/http2/HpackDecoder.java
index 528f71481a..b9c889eec0 100644
--- a/java/org/apache/coyote/http2/HpackDecoder.java
+++ b/java/org/apache/coyote/http2/HpackDecoder.java
@@ -238,10 +238,6 @@ public class HpackDecoder {
             return Hpack.STATIC_TABLE[index].name;
         } else {
             // index is 1 based
-            if (index > Hpack.STATIC_TABLE_LENGTH + filledTableSlots) {
-                throw new 
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid", 
Integer.valueOf(index),
-                        Integer.valueOf(Hpack.STATIC_TABLE_LENGTH), 
Integer.valueOf(filledTableSlots)));
-            }
             int adjustedIndex = getRealIndex(index - 
Hpack.STATIC_TABLE_LENGTH);
             Hpack.HeaderField res = headerTable[adjustedIndex];
             if (res == null) {
@@ -263,10 +259,6 @@ public class HpackDecoder {
             addStaticTableEntry(index);
         } else {
             // index is 1 based
-            if (index > Hpack.STATIC_TABLE_LENGTH + filledTableSlots) {
-                throw new 
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid", 
Integer.valueOf(index),
-                        Integer.valueOf(Hpack.STATIC_TABLE_LENGTH), 
Integer.valueOf(filledTableSlots)));
-            }
             int adjustedIndex = getRealIndex(index - 
Hpack.STATIC_TABLE_LENGTH);
             if (log.isTraceEnabled()) {
                 log.trace(sm.getString("hpackdecoder.useDynamic", 
Integer.valueOf(adjustedIndex)));
@@ -287,15 +279,14 @@ public class HpackDecoder {
      * @return the real index into the array
      */
     int getRealIndex(int index) throws HpackException {
-        // the index is one based, but our table is zero based, hence -1
-        // also because of our ring buffer set up the indexes are reversed
+        // The index is one based, but our table is zero based
+        // Also, because of our ring buffer set up, the indexes are reversed
         // index = 1 is at position firstSlotPosition + filledSlots
-        int realIndex = (firstSlotPosition + (filledTableSlots - index)) % 
headerTable.length;
-        if (realIndex < 0) {
+        if (index < 1 || index > filledTableSlots) {
             throw new 
HpackException(sm.getString("hpackdecoder.headerTableIndexInvalid", 
Integer.valueOf(index),
                     Integer.valueOf(Hpack.STATIC_TABLE_LENGTH), 
Integer.valueOf(filledTableSlots)));
         }
-        return realIndex;
+        return (firstSlotPosition + (filledTableSlots - index)) % 
headerTable.length;
     }
 
     private void addStaticTableEntry(int index) throws HpackException {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a96b64c788..aebad94f7f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -127,6 +127,10 @@
         clearing the previous value whether the new value is valid or not and
         ignoring any invalid new value. (markt)
       </fix>
+      <scode>
+        Refactor the calculation of the real index in the HPACK dynamic header
+        table implementation to reduce code duplication. (markt)
+      </scode>
     </changelog>
   </subsection>
 </section>


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

Reply via email to