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

commit 19fbaf01313f1aeec52982c21dd5085751a2ba63
Author: opencode <[email protected]>
AuthorDate: Thu Nov 5 23:44:23 2026 +0100

    Document PoolProperties defaults and tidy its comments
    
    Show the pool name in the toString() dump the javadoc promises, correct the 
getValueAschar spelling note, and state that minIdle's default is fixed at 
construction rather than following a later initialSize change. Add tests for 
the name and the fixed default. Remove one-line field comments that only 
repeated the field names.
---
 .../apache/tomcat/jdbc/pool/PoolConfiguration.java | 26 ++++-----
 .../apache/tomcat/jdbc/pool/PoolProperties.java    | 63 ++++------------------
 .../tomcat/jdbc/pool/TestPoolProperties.java       | 22 ++++++++
 3 files changed, 47 insertions(+), 64 deletions(-)

diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
index ea68022bfc..7f26fe7f2d 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
@@ -379,12 +379,13 @@ public interface PoolConfiguration {
 
     /**
      * The minimum number of established connections that should be kept in 
the pool at all times. The connection pool
-     * can shrink below this number if validation queries fail and connections 
get closed. Default value is derived from
-     * {@link #getInitialSize()} (also see {@link 
#setTestWhileIdle(boolean)}). The eviction run normally keeps the
-     * total number of connections in the pool - idle plus busy - at or above 
this value, hence the number of actual
-     * connections can be between {@link #getMinIdle()} and somewhere between 
{@link #getMaxIdle()} and
-     * {@link #getMaxActive()}. A connection left over from an earlier pool 
generation is released regardless, so an
-     * explicit idle check after a purge can take the pool below the floor.
+     * can shrink below this number if validation queries fail and connections 
get closed. The default is the value
+     * {@link #getInitialSize()} had when this configuration was constructed; 
changing {@code initialSize} later does
+     * not move it, so set this explicitly to change the floor (also see 
{@link #setTestWhileIdle(boolean)}). The
+     * eviction run normally keeps the total number of connections in the pool 
- idle plus busy - at or above this
+     * value, hence the number of actual connections can be between {@link 
#getMinIdle()} and somewhere between
+     * {@link #getMaxIdle()} and {@link #getMaxActive()}. A connection left 
over from an earlier pool generation is
+     * released regardless, so an explicit idle check after a purge can take 
the pool below the floor.
      *
      * @return the minimum number of idle or established connections
      */
@@ -392,12 +393,13 @@ public interface PoolConfiguration {
 
     /**
      * The minimum number of established connections that should be kept in 
the pool at all times. The connection pool
-     * can shrink below this number if validation queries fail and connections 
get closed. Default value is derived from
-     * {@link #getInitialSize()} (also see {@link 
#setTestWhileIdle(boolean)}). The eviction run normally keeps the
-     * total number of connections in the pool - idle plus busy - at or above 
this value, hence the number of actual
-     * connections can be between {@link #getMinIdle()} and somewhere between 
{@link #getMaxIdle()} and
-     * {@link #getMaxActive()}. A connection left over from an earlier pool 
generation is released regardless, so an
-     * explicit idle check after a purge can take the pool below the floor.
+     * can shrink below this number if validation queries fail and connections 
get closed. The default is the value
+     * {@link #getInitialSize()} had when this configuration was constructed; 
changing {@code initialSize} later does
+     * not move it, so set this explicitly to change the floor (also see 
{@link #setTestWhileIdle(boolean)}). The
+     * eviction run normally keeps the total number of connections in the pool 
- idle plus busy - at or above this
+     * value, hence the number of actual connections can be between {@link 
#getMinIdle()} and somewhere between
+     * {@link #getMaxIdle()} and {@link #getMaxActive()}. A connection left 
over from an earlier pool generation is
+     * released regardless, so an explicit idle check after a purge can take 
the pool below the floor.
      *
      * @param minIdle the minimum number of idle or established connections
      */
diff --git 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
index d2516e7e41..8acabf67b0 100644
--- 
a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
+++ 
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
@@ -74,61 +74,39 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
      * Counter for tracking the number of pools created.
      */
     protected static final AtomicInteger poolCounter = new AtomicInteger(0);
-    /** Database-specific properties. */
     private volatile Properties dbProperties = new Properties();
-    /** The JDBC connection URL. */
     private volatile String url = null;
-    /** The JDBC driver class name. */
     private volatile String driverClassName = null;
-    /** The default auto-commit setting for connections. */
     private volatile Boolean defaultAutoCommit = null;
-    /** The default read-only setting for connections. */
     private volatile Boolean defaultReadOnly = null;
-    /** The default transaction isolation level. */
     private volatile int defaultTransactionIsolation = 
DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION;
-    /** The default catalog for connections. */
     private volatile String defaultCatalog = null;
-    /** Additional connection properties. */
     private volatile String connectionProperties;
     /** Keys the last parse of {@link #connectionProperties} contributed to 
{@link #dbProperties}. */
     private volatile Set<String> connectionPropertyKeys = 
Collections.emptySet();
-    /** The initial number of connections in the pool. */
     private volatile int initialSize = 10;
-    /** The maximum number of active connections. */
     private volatile int maxActive = DEFAULT_MAX_ACTIVE;
-    /** The maximum number of idle connections. */
     private volatile int maxIdle = maxActive;
-    /** The minimum number of idle connections. */
+    /**
+     * The minimum number of idle connections, initialized once from
+     * {@link #initialSize} at construction; a later change to
+     * {@code initialSize} does not move it.
+     */
     private volatile int minIdle = initialSize;
-    /** The maximum wait time in milliseconds for a connection. */
     private volatile int maxWait = 30000;
-    /** The SQL query used for validation. */
     private volatile String validationQuery;
-    /** The validation query timeout in seconds. */
     private volatile int validationQueryTimeout = -1;
-    /** The fully qualified class name of the validator. */
     private volatile String validatorClassName;
-    /** The validator instance. */
     private transient volatile Validator validator;
-    /** Whether to validate connections on borrow. */
     private volatile boolean testOnBorrow = false;
-    /** Whether to validate connections on return. */
     private volatile boolean testOnReturn = false;
-    /** Whether to validate idle connections. */
     private volatile boolean testWhileIdle = false;
-    /** The time between eviction runs in milliseconds. */
     private volatile int timeBetweenEvictionRunsMillis = 5000;
-    /** The number of connections to test per eviction run. */
     private volatile int numTestsPerEvictionRun;
-    /** The minimum idle time before a connection is eligible for eviction. */
     private volatile int minEvictableIdleTimeMillis = 60000;
-    /** Whether to allow access to the underlying connection. */
     private volatile boolean accessToUnderlyingConnectionAllowed = true;
-    /** Whether to remove abandoned connections. */
     private volatile boolean removeAbandoned = false;
-    /** The timeout in seconds for abandoned connection removal. */
     private volatile int removeAbandonedTimeout = 60;
-    /** Whether to log abandoned connections. */
     private volatile boolean logAbandoned = false;
     /**
      * The pool name. This default is the fallback for a pool nobody named: a
@@ -141,43 +119,24 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
      * is not in the name any more.
      */
     private volatile String name = "Tomcat Connection Pool[" + 
(poolCounter.addAndGet(1)) + "]";
-    /** The database password. */
     private volatile String password;
-    /** The database username. */
     private volatile String username;
-    /** The validation interval in milliseconds. */
     private volatile long validationInterval = 3000;
-    /** Whether JMX registration is enabled. */
     private volatile boolean jmxEnabled = true;
-    /** The SQL to execute on connection creation. */
     private volatile String initSQL;
-    /** Whether to validate connections on creation. */
     private volatile boolean testOnConnect = false;
-    /** The JDBC interceptors configuration. */
     private volatile String jdbcInterceptors = null;
-    /** Whether to use a fair queue for connection requests. */
     private volatile boolean fairQueue = true;
-    /** Whether to use equals for object comparison. */
     private volatile boolean useEquals = true;
-    /** The percentage threshold for abandoning connections. */
     private volatile int abandonWhenPercentageFull = 0;
-    /** The maximum age of a connection in milliseconds. */
     private volatile long maxAge = 0;
-    /** Whether to use locking for thread safety. */
     private volatile boolean useLock = false;
-    /** The interceptor definitions. */
     private volatile InterceptorDefinition[] interceptors = null;
-    /** The suspect timeout in seconds. */
     private volatile int suspectTimeout = 0;
-    /** The underlying data source. */
     private volatile Object dataSource = null;
-    /** The JNDI name of the data source. */
     private volatile String dataSourceJNDI = null;
-    /** Whether alternate usernames are allowed. */
     private volatile boolean alternateUsernameAllowed = false;
-    /** Whether to commit on connection return. */
     private volatile boolean commitOnReturn = false;
-    /** Whether to rollback on connection return. */
     private volatile boolean rollbackOnReturn = false;
     /**
      * Whether to use a disposable connection facade.
@@ -186,11 +145,8 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
      */
     @Deprecated
     private volatile boolean useDisposableConnectionFacade = true;
-    /** Whether to log validation errors. */
     private volatile boolean logValidationErrors = false;
-    /** Whether to propagate interrupt state. */
     private volatile boolean propagateInterruptState = false;
-    /** Whether to ignore exceptions during pre-load. */
     private volatile boolean ignoreExceptionOnPreLoad = false;
     /**
      * Whether to use a statement facade.
@@ -1001,6 +957,9 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
     public String toString() {
         StringBuilder buf = new StringBuilder("ConnectionPool[");
         try {
+            // object_name has no getter of its own: the factory applies it to
+            // the pool name, which the dump therefore prints explicitly.
+            buf.append("name=").append(name).append("; ");
             String[] fields = DataSourceFactory.ALL_PROPERTIES;
             for (String field : fields) {
                 final String[] prefix = new String[] { "get", "is" };
@@ -1982,9 +1941,9 @@ public class PoolProperties implements PoolConfiguration, 
Cloneable, Serializabl
         /**
          * Returns the property value as a char.
          * <p>
-         * The method name is misspaced (capital {@code A} in {@code AsChar})
-         * in the upstream API. It is left as published so the existing public
-         * signature is not broken.
+         * The method name has a lower-case {@code c} ({@code getValueAschar}
+         * rather than {@code getValueAsChar}) in the upstream API. It is left
+         * as published so the existing public signature is not broken.
          *
          * @param def the default value if the property is null or invalid
          *
diff --git 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/TestPoolProperties.java
 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/TestPoolProperties.java
index 8366a2ff53..c9e37b11fd 100644
--- 
a/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/TestPoolProperties.java
+++ 
b/modules/jdbc-pool/src/test/java/org/apache/tomcat/jdbc/pool/TestPoolProperties.java
@@ -152,6 +152,28 @@ class TestPoolProperties {
                         + "factory path");
     }
 
+    @Test
+    void theMinIdleDefaultIsFixedAtConstruction() {
+        PoolProperties properties = new PoolProperties();
+        int constructedDefault = properties.getMinIdle();
+
+        properties.setInitialSize(2);
+
+        Assertions.assertEquals(2, properties.getInitialSize());
+        Assertions.assertEquals(constructedDefault, properties.getMinIdle(),
+                "minIdle's default is the initialSize value at construction; 
changing"
+                        + " initialSize later does not move the floor");
+    }
+
+    @Test
+    void toStringShowsThePoolName() {
+        PoolProperties properties = new PoolProperties();
+        properties.setName("myPool");
+
+        
Assertions.assertTrue(properties.toString().startsWith("ConnectionPool[name=myPool;"),
+                "the dump must show the pool name its javadoc promises, was: " 
+ properties);
+    }
+
     @Test
     void toStringDoesNotPrintTheConfiguredDataSourceObject() {
         PoolProperties properties = new PoolProperties();


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

Reply via email to