This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
commit a721f0cceee2528af1bff76be8fe80ab01769efa Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jun 23 09:33:43 2023 -0400 CPDSConnectionFactory.makeObject() does not need to wrap and rethrow SQLException. --- src/changes/changes.xml | 3 ++ .../dbcp2/datasources/CPDSConnectionFactory.java | 34 ++++++++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 361409d6..1d8253ff 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -118,6 +118,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="ggregory" type="fix" due-to="Gary Gregory"> Throw SQLException instead of NullPointerException when the connection is already closed. </action> + <action dev="ggregory" type="fix" due-to="Gary Gregory"> + CPDSConnectionFactory.makeObject() does not need to wrap and rethrow SQLException. + </action> <!-- ADD --> <action dev="ggregory" type="add" due-to="Gary Gregory"> Add and use AbandonedTrace#setLastUsed(Instant). diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java index 9d04001c..ce0f08ce 100644 --- a/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java +++ b/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java @@ -304,26 +304,22 @@ final class CPDSConnectionFactory } @Override - public synchronized PooledObject<PooledConnectionAndInfo> makeObject() { - try { - PooledConnection pc = null; - if (userPassKey.getUserName() == null) { - pc = cpds.getPooledConnection(); - } else { - pc = cpds.getPooledConnection(userPassKey.getUserName(), userPassKey.getPassword()); - } - if (pc == null) { - throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); - } - // should we add this object as a listener or the pool. - // consider the validateObject method in decision - pc.addConnectionEventListener(this); - final PooledConnectionAndInfo pci = new PooledConnectionAndInfo(pc, userPassKey); - pcMap.put(pc, pci); - return new DefaultPooledObject<>(pci); - } catch (final SQLException e) { - throw new RuntimeException(e.getMessage()); + public synchronized PooledObject<PooledConnectionAndInfo> makeObject() throws SQLException { + PooledConnection pc = null; + if (userPassKey.getUserName() == null) { + pc = cpds.getPooledConnection(); + } else { + pc = cpds.getPooledConnection(userPassKey.getUserName(), userPassKey.getPassword()); + } + if (pc == null) { + throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); } + // should we add this object as a listener or the pool. + // consider the validateObject method in decision + pc.addConnectionEventListener(this); + final PooledConnectionAndInfo pci = new PooledConnectionAndInfo(pc, userPassKey); + pcMap.put(pc, pci); + return new DefaultPooledObject<>(pci); } @Override