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

commit 7e26d2ca885a380c33336d8b582434afd27d16de
Author: opencode <[email protected]>
AuthorDate: Mon Oct 26 16:07:57 2026 +0100

    Round-trip connection properties through DataSourceProxy
    
    DataSourceProxy.setConnectionProperties() re-implemented the parsing by
    hand, merging the pairs into the database properties but never storing the
    raw string. getConnectionProperties() therefore reported null for a value
    that had just been set, and the connectionProperties attribute on the
    proxy's JMX/bean view, toString() and read-modify-write consumers all saw
    stale null - unlike the same method on PoolProperties and on the pool's
    JMX wrapper, which store it.
    
    The proxy setter now delegates to PoolProperties, making the three
    surfaces behave identically.
---
 .../apache/tomcat/jdbc/pool/DataSourceProxy.java   | 19 ++++++++-----------
 .../tomcat/jdbc/pool/TestPoolProperties.java       | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 11 deletions(-)

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 d51cd1438d..6b66d57631 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
@@ -20,7 +20,6 @@ import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
-import java.util.Iterator;
 import java.util.Properties;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -560,17 +559,15 @@ public class DataSourceProxy implements PoolConfiguration 
{
     @Override
     public void setConnectionProperties(String properties) {
         try {
-            Properties prop = DataSourceFactory.getProperties(properties);
-            Iterator<?> i = prop.keySet().iterator();
-            while (i.hasNext()) {
-                String key = (String) i.next();
-                String value = prop.getProperty(key);
-                getPoolProperties().getDbProperties().setProperty(key, value);
-            }
-
-        } catch (Exception x) {
+            // Delegate so the raw string is stored as well as parsed: a
+            // hand-rolled merge into the database properties left
+            // getConnectionProperties() reporting null for a value that
+            // was just set, unlike every other implementation of the
+            // interface (PoolProperties itself and the pool's JMX wrapper).
+            getPoolProperties().setConnectionProperties(properties);
+        } catch (RuntimeException x) {
             log.error("Unable to parse connection properties.", x);
-            throw new RuntimeException(x);
+            throw x;
         }
     }
 
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 4332ebc780..0aeb72cdda 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
@@ -89,6 +89,28 @@ class TestPoolProperties {
                 "getPoolName() must still work after close()");
     }
 
+    @Test
+    void setConnectionPropertiesRoundTripsThroughTheProxy() {
+        PoolProperties properties = new PoolProperties();
+        DataSourceProxy proxy = new DataSourceProxy(properties);
+
+        proxy.setConnectionProperties("first=one;second=two");
+
+        Assertions.assertEquals("first=one;second=two", 
proxy.getConnectionProperties(),
+                "the proxy setter must store the raw string like every other "
+                        + "implementation of the interface does");
+        // the same call must keep parsing the pairs into the driver
+        // properties the pool connects with
+        Assertions.assertEquals("one", 
properties.getDbProperties().getProperty("first"),
+                "the parsed pairs must still reach the database properties");
+        Assertions.assertEquals("two", 
properties.getDbProperties().getProperty("second"),
+                "the parsed pairs must still reach the database properties");
+
+        proxy.setConnectionProperties(null);
+        Assertions.assertNull(proxy.getConnectionProperties(),
+                "clearing the configuration must round-trip as well");
+    }
+
     @Test
     void toStringMasksThePasswordButStillShowsTheConfiguration() {
         PoolProperties properties = new PoolProperties();


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

Reply via email to