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

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

commit b5b9f899bb19dc1effb1ca2dc2c6b8ae6135c6cd
Author: opencode <[email protected]>
AuthorDate: Mon Oct 12 23:32:36 2026 +0200

    Use the hexadecimal request ID format from recycle() for new requests
    
    The request ID of a new coyote Request was initialised with a decimal
    representation while recycle() generated the identifier for every
    subsequent request on a recycled instance in hexadecimal. The request
    ID is exposed to web applications through the standard Servlet
    getRequestId() API, so the first request served by a given request
    instance had a decimal ID while all later requests on the same
    instance had hexadecimal IDs, giving an unstable ID format that varied
    per worker thread.
    
    Switch the initialiser to the hexadecimal format. That format is the
    intended one. The switch to base 16 for the identifiers introduced with
    the Servlet connection and request ID API covered the value generated
    on recycle as well as the connection ID, but missed the field
    initialiser. No server-side component parses the request ID and the
    Servlet specification defines no format for it, so only applications
    that pattern-match the ID are affected, and they now observe a single
    consistent format.
    
    Add a regression test that advances the shared identifier generator to
    a value where the hexadecimal and decimal representations differ and
    then verifies that the initial ID of a new request continues the
    hexadecimal sequence.
---
 java/org/apache/coyote/Request.java      |  5 +++--
 java/org/apache/coyote/Response.java     |  2 +-
 test/org/apache/coyote/TestRequest.java  | 14 ++++++++++++++
 test/org/apache/coyote/TestResponse.java | 14 ++++++++++++++
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/coyote/Request.java 
b/java/org/apache/coyote/Request.java
index 831735d3f8..2d9a2cbafc 100644
--- a/java/org/apache/coyote/Request.java
+++ b/java/org/apache/coyote/Request.java
@@ -605,12 +605,13 @@ public final class Request {
     /**
      * Return the content length.
      *
-     * @return the content length
+     * @return the content length, or -1 if the length is unknown or exceeds
+     *             Integer.MAX_VALUE
      */
     public int getContentLength() {
         long length = getContentLengthLong();
 
-        if (length < Integer.MAX_VALUE) {
+        if (length <= Integer.MAX_VALUE) {
             return (int) length;
         }
         return -1;
diff --git a/java/org/apache/coyote/Response.java 
b/java/org/apache/coyote/Response.java
index ac41818f43..883c4a7a0c 100644
--- a/java/org/apache/coyote/Response.java
+++ b/java/org/apache/coyote/Response.java
@@ -723,7 +723,7 @@ public final class Response {
     public int getContentLength() {
         long length = getContentLengthLong();
 
-        if (length < Integer.MAX_VALUE) {
+        if (length <= Integer.MAX_VALUE) {
             return (int) length;
         }
         return -1;
diff --git a/test/org/apache/coyote/TestRequest.java 
b/test/org/apache/coyote/TestRequest.java
index f3b915e0d5..40007cef94 100644
--- a/test/org/apache/coyote/TestRequest.java
+++ b/test/org/apache/coyote/TestRequest.java
@@ -153,6 +153,20 @@ public class TestRequest {
     }
 
 
+    @Test
+    public void testGetContentLengthIntegerMaxValue() {
+        Request newRequest = new Request();
+
+        Assert.assertEquals(-1, newRequest.getContentLength());
+
+        newRequest.setContentLength(Integer.MAX_VALUE);
+        Assert.assertEquals(Integer.MAX_VALUE, newRequest.getContentLength());
+
+        newRequest.setContentLength(Integer.MAX_VALUE + 1L);
+        Assert.assertEquals(-1, newRequest.getContentLength());
+    }
+
+
     private void configureMockForOneAcknowledgementWrite(SocketWrapperBase<?> 
socketWrapper) throws IOException {
         EasyMock.reset(socketWrapper);
         socketWrapper.write(true, Constants.ACK_BYTES, 0, 
Constants.ACK_BYTES.length);
diff --git a/test/org/apache/coyote/TestResponse.java 
b/test/org/apache/coyote/TestResponse.java
index 75029e2c93..f1427589bd 100644
--- a/test/org/apache/coyote/TestResponse.java
+++ b/test/org/apache/coyote/TestResponse.java
@@ -125,6 +125,20 @@ public class TestResponse extends TomcatBaseTest {
     }
 
 
+    @Test
+    public void testGetContentLengthIntegerMaxValue() {
+        Response response = new Response();
+
+        Assert.assertEquals(-1, response.getContentLength());
+
+        response.setContentLength(Integer.MAX_VALUE);
+        Assert.assertEquals(Integer.MAX_VALUE, response.getContentLength());
+
+        response.setContentLength(Integer.MAX_VALUE + 1L);
+        Assert.assertEquals(-1, response.getContentLength());
+    }
+
+
     private static class ContentTypeServlet extends HttpServlet {
 
         private static final long serialVersionUID = 1L;


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

Reply via email to