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

markt-asf 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 ff885d7732 Fix BZ 70296 - Use longs for StringCache stats
ff885d7732 is described below

commit ff885d7732c07dbf64843e90d4694797e5d80ee5
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Nov 11 20:13:31 2026 +0000

    Fix BZ 70296 - Use longs for StringCache stats
---
 java/org/apache/tomcat/util/buf/StringCache.java | 46 +++++++++++++++++++++---
 webapps/docs/changelog.xml                       |  5 +++
 2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/tomcat/util/buf/StringCache.java 
b/java/org/apache/tomcat/util/buf/StringCache.java
index c7b762f1b5..f481a3d075 100644
--- a/java/org/apache/tomcat/util/buf/StringCache.java
+++ b/java/org/apache/tomcat/util/buf/StringCache.java
@@ -118,13 +118,13 @@ public class StringCache {
     /**
      * Access count.
      */
-    protected static int accessCount = 0;
+    protected static long accessCount = 0;
 
 
     /**
      * Hit count.
      */
-    protected static int hitCount = 0;
+    protected static long hitCount = 0;
 
 
     // ------------------------------------------------------------ Properties
@@ -211,28 +211,64 @@ public class StringCache {
 
 
     /**
-     * Returns the total number of cache lookups performed.
+     * Returns the total number of cache lookups performed. If the total is 
more than {@link Integer#MAX_VALUE},
+     * {@link Integer#MAX_VALUE} is returned.
      *
      * @return the access count
+     *
+     * @deprecated Use {@link #getAccessCountLong()}. This method will be 
removed in Tomcat 12.0.x onwards.
      */
+    @Deprecated
     public int getAccessCount() {
+        long accessCount = StringCache.accessCount;
+        if (accessCount > Integer.MAX_VALUE) {
+            return Integer.MAX_VALUE;
+        } else {
+            return (int) accessCount;
+        }
+    }
+
+
+    /**
+     * Returns the total number of cache lookups performed.
+     *
+     * @return the access count
+     */
+    public long getAccessCountLong() {
         return accessCount;
     }
 
+    /**
+     * Returns the number of cache hits. If the total is more than {@link 
Integer#MAX_VALUE}, {@link Integer#MAX_VALUE}
+     * is returned.
+     *
+     * @return the hit count
+     *
+     * @deprecated Use {@link #getHitCountLong()}. This method will be removed 
in Tomcat 12.0.x onwards.
+     */
+    @Deprecated
+    public int getHitCount() {
+        long hitCount = StringCache.hitCount;
+        if (hitCount > Integer.MAX_VALUE) {
+            return Integer.MAX_VALUE;
+        } else {
+            return (int) hitCount;
+        }
+    }
+
 
     /**
      * Returns the number of cache hits.
      *
      * @return the hit count
      */
-    public int getHitCount() {
+    public long getHitCountLong() {
         return hitCount;
     }
 
 
     // -------------------------------------------------- Public Static Methods
 
-
     /**
      * Resets all cache statistics and clears the cache.
      */
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6d9b37fd06..338e82a97e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -118,6 +118,11 @@
         <bug>70288</bug>: Fix bug that could cause request body truncation with
         HTTP/2. Based on a patch by Alberto Limón. (markt)
       </fix>
+      <fix>
+        <bug>70296</bug>: Update the <code>StringCache</code> to report access
+        counts and hit counts as <code>long</code> rather than 
<code>int</code>.
+        (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">


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

Reply via email to