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

rmaucher 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 01750278d9 Fix minor consistency issues
01750278d9 is described below

commit 01750278d9880f4025ac9b23e55ef056acdb5f84
Author: remm <[email protected]>
AuthorDate: Thu May 28 12:42:09 2026 +0200

    Fix minor consistency issues
    
    Document.
---
 .../apache/catalina/util/LocalStrings.properties   |   1 +
 java/org/apache/catalina/util/ResourceSet.java     | 117 +++++++++++++++++++--
 java/org/apache/catalina/util/SessionConfig.java   |   3 +
 .../catalina/util/TimeBucketCounterBase.java       |   4 +
 java/org/apache/catalina/util/XMLWriter.java       |   5 +-
 5 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/java/org/apache/catalina/util/LocalStrings.properties 
b/java/org/apache/catalina/util/LocalStrings.properties
index a23c8b74f6..30d8a0711c 100644
--- a/java/org/apache/catalina/util/LocalStrings.properties
+++ b/java/org/apache/catalina/util/LocalStrings.properties
@@ -54,4 +54,5 @@ sessionIdGeneratorBase.random=Exception initializing random 
number generator of
 sessionIdGeneratorBase.randomAlgorithm=Exception initializing random number 
generator using algorithm [{0}]
 sessionIdGeneratorBase.randomProvider=Exception initializing random number 
generator using provider [{0}]
 
+timebucket.invalidDuration=The duration (in seconds) must be a positive 
integer, was [{0}]
 timebucket.maintenance.error=Error processing periodic maintenance
diff --git a/java/org/apache/catalina/util/ResourceSet.java 
b/java/org/apache/catalina/util/ResourceSet.java
index 17cd977a12..f7a82f7451 100644
--- a/java/org/apache/catalina/util/ResourceSet.java
+++ b/java/org/apache/catalina/util/ResourceSet.java
@@ -20,6 +20,7 @@ package org.apache.catalina.util;
 import java.io.Serial;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 
 import org.apache.tomcat.util.res.StringManager;
 
@@ -27,7 +28,7 @@ import org.apache.tomcat.util.res.StringManager;
 /**
  * Extended implementation of <strong>HashSet</strong> that includes a 
<code>locked</code> property. This class can be
  * used to safely expose resource path sets to user classes without having to 
clone them in order to avoid
- * modifications. When first created, a <code>ResourceMap</code> is not locked.
+ * modifications. When first created, a <code>ResourceSet</code> is not locked.
  *
  * @param <T> The type of elements in the Set
  */
@@ -123,19 +124,41 @@ public final class ResourceSet<T> extends HashSet<T> {
 
 
     /**
-     * {@inheritDoc}
+     * Check the lock state and throw an exception if locked.
      *
      * @exception IllegalStateException if this set is currently locked
      */
-    @Override
-    public boolean add(T o) {
+    private void checkLocked() {
         if (locked) {
             throw new 
IllegalStateException(sm.getString("resourceSet.locked"));
         }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public boolean add(T o) {
+        checkLocked();
         return super.add(o);
     }
 
 
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public boolean addAll(Collection<? extends T> c) {
+        checkLocked();
+        return super.addAll(c);
+    }
+
+
     /**
      * {@inheritDoc}
      *
@@ -144,9 +167,7 @@ public final class ResourceSet<T> extends HashSet<T> {
     @Override
     public void clear() {
 
-        if (locked) {
-            throw new 
IllegalStateException(sm.getString("resourceSet.locked"));
-        }
+        checkLocked();
         super.clear();
 
     }
@@ -159,10 +180,90 @@ public final class ResourceSet<T> extends HashSet<T> {
      */
     @Override
     public boolean remove(Object o) {
+        checkLocked();
+        return super.remove(o);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        checkLocked();
+        return super.removeAll(c);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        checkLocked();
+        return super.retainAll(c);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public boolean removeIf(java.util.function.Predicate<? super T> filter) {
+        checkLocked();
+        return super.removeIf(filter);
+    }
+
+
+    /**
+     * {@inheritDoc}
+     *
+     * @exception IllegalStateException if this set is currently locked
+     */
+    @Override
+    public Iterator<T> iterator() {
         if (locked) {
+            return new LockedIterator(super.iterator());
+        }
+        return super.iterator();
+    }
+
+
+    /**
+     * An iterator that throws {@link IllegalStateException} on {@code 
remove()} when the set is locked.
+     */
+    private class LockedIterator implements Iterator<T> {
+
+        private final Iterator<T> delegate;
+
+
+        private LockedIterator(Iterator<T> delegate) {
+            this.delegate = delegate;
+        }
+
+
+        @Override
+        public boolean hasNext() {
+            return delegate.hasNext();
+        }
+
+
+        @Override
+        public T next() {
+            return delegate.next();
+        }
+
+
+        @Override
+        public void remove() {
             throw new 
IllegalStateException(sm.getString("resourceSet.locked"));
         }
-        return super.remove(o);
     }
 
 
diff --git a/java/org/apache/catalina/util/SessionConfig.java 
b/java/org/apache/catalina/util/SessionConfig.java
index 5c03c2f4e4..a2106fb817 100644
--- a/java/org/apache/catalina/util/SessionConfig.java
+++ b/java/org/apache/catalina/util/SessionConfig.java
@@ -81,6 +81,9 @@ public class SessionConfig {
      */
     public static String getSessionCookiePath(Context context) {
 
+        if (context == null) {
+            return null;
+        }
         SessionCookieConfig scc = 
context.getServletContext().getSessionCookieConfig();
 
         String contextPath = context.getSessionCookiePath();
diff --git a/java/org/apache/catalina/util/TimeBucketCounterBase.java 
b/java/org/apache/catalina/util/TimeBucketCounterBase.java
index 67c567d1e1..01a51b1ec0 100644
--- a/java/org/apache/catalina/util/TimeBucketCounterBase.java
+++ b/java/org/apache/catalina/util/TimeBucketCounterBase.java
@@ -58,9 +58,13 @@ public abstract class TimeBucketCounterBase {
      * @param executorService the executor service that will be used to run 
the maintenance task
      *
      * @throws NullPointerException if executorService is <code>null</code>.
+     * @throws IllegalArgumentException if bucketDuration is not strictly 
positive
      */
     public TimeBucketCounterBase(int bucketDuration, ScheduledExecutorService 
executorService) {
         Objects.requireNonNull(executorService);
+        if (bucketDuration <= 0) {
+            throw new 
IllegalArgumentException(sm.getString("timebucket.invalidDuration", 
Integer.valueOf(bucketDuration)));
+        }
         this.executorService = executorService;
         this.bucketDuration = bucketDuration;
 
diff --git a/java/org/apache/catalina/util/XMLWriter.java 
b/java/org/apache/catalina/util/XMLWriter.java
index 85e425bfff..146136cccc 100644
--- a/java/org/apache/catalina/util/XMLWriter.java
+++ b/java/org/apache/catalina/util/XMLWriter.java
@@ -22,7 +22,8 @@ import java.io.Writer;
 import org.apache.tomcat.util.security.Escape;
 
 /**
- * XMLWriter helper class.
+ * XMLWriter helper class. writeText is the only method in the class doing
+ * XML escaping.
  */
 public class XMLWriter {
 
@@ -217,7 +218,7 @@ public class XMLWriter {
 
 
     /**
-     * Write text.
+     * Write text. It will be escaped for XML.
      *
      * @param text Text to append
      */


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

Reply via email to