This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit a27da167a016384f1817db987a38fe163f1a2ddf Author: opencode <[email protected]> AuthorDate: Mon Oct 26 14:42:11 2026 +0100 Do not fail getPoolName() before the pool exists DataSourceProxy.getPoolName() dereferenced the lazily created ConnectionPool, so the PoolConfiguration getter documented as returning the same value as getName() threw NullPointerException on a configured but not yet started DataSource, and again after close(). Delegate to the pool properties instead. That is also where ConnectionPool.getName() resolves the value, so behavior after start-up is unchanged. Cover the pre-creation and post-close states in TestPoolProperties. --- .../org/apache/tomcat/jdbc/pool/DataSourceProxy.java | 2 +- .../org/apache/tomcat/jdbc/pool/TestPoolProperties.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index 3e3eb44214..7954be2b99 100644 --- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java +++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java @@ -355,7 +355,7 @@ public class DataSourceProxy implements PoolConfiguration { @Override public String getPoolName() { - return pool.getName(); + return getPoolProperties().getPoolName(); } 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 9896410af9..4332ebc780 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 @@ -72,6 +72,23 @@ class TestPoolProperties { Assertions.assertEquals(0, stack.size(), "All brackets should have been closed"); } + @Test + void poolNameIsAvailableBeforeThePoolIsCreatedAndAfterClose() { + PoolProperties properties = new PoolProperties(); + properties.setName("test-pool"); + DataSourceProxy proxy = new DataSourceProxy(properties); + + Assertions.assertEquals("test-pool", proxy.getPoolName(), + "getPoolName() must not require a running pool"); + Assertions.assertEquals(proxy.getName(), proxy.getPoolName(), + "getPoolName() and getName() must agree"); + + proxy.close(); + + Assertions.assertEquals("test-pool", proxy.getPoolName(), + "getPoolName() must still work after close()"); + } + @Test void toStringMasksThePasswordButStillShowsTheConfiguration() { PoolProperties properties = new PoolProperties(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
