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


The following commit(s) were added to refs/heads/master by this push:
     new 35863ae  [DBCP-553] 
org.apache.commons.dbcp2.PoolablePreparedStatement.passivate() should close ALL 
of its resources even when an exception occurs.
35863ae is described below

commit 35863aec26dca6ca6dd315962d9dd8d3a4a11ec2
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Tue Jul 30 19:28:18 2019 -0400

    [DBCP-553]
    org.apache.commons.dbcp2.PoolablePreparedStatement.passivate() should
    close ALL of its resources even when an exception occurs.
---
 src/changes/changes.xml                            |  3 +++
 .../commons/dbcp2/PoolablePreparedStatement.java   | 23 ++++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 13e1356..99132a4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -130,6 +130,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" issue="DBCP-552" due-to="Gary 
Gregory">
         org.apache.commons.dbcp2.DelegatingConnection.passivate() should close 
ALL of its resources even when an exception occurs.
       </action>
+      <action dev="ggregory" type="update" issue="DBCP-553" due-to="Gary 
Gregory">
+        org.apache.commons.dbcp2.PoolablePreparedStatement.passivate() should 
close ALL of its resources even when an exception occurs.
+      </action>
     </release>
     <release version="2.6.0" date="2019-02-14" description="This is a minor 
release, including bug fixes and enhancements.">
       <action dev="chtompki" type="add" issue="DBCP-534" due-to="Peter Wicks">
diff --git 
a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java 
b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
index 222de96..456f5ab 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java
@@ -20,6 +20,7 @@ package org.apache.commons.dbcp2;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.pool2.KeyedObjectPool;
@@ -50,7 +51,7 @@ public class PoolablePreparedStatement<K> extends 
DelegatingPreparedStatement {
     private volatile boolean batchAdded = false;
 
     /**
-     * Constructor
+     * Constructor.
      *
      * @param stmt
      *            my underlying {@link PreparedStatement}
@@ -132,13 +133,23 @@ public class PoolablePreparedStatement<K> extends 
DelegatingPreparedStatement {
         // ResultSet's when it is closed.
         // FIXME The PreparedStatement we're wrapping should handle this for 
us.
         // See bug 17301 for what could happen when ResultSets are closed 
twice.
-        final List<AbandonedTrace> resultSets = getTrace();
-        if (resultSets != null) {
-            final ResultSet[] set = resultSets.toArray(new 
ResultSet[resultSets.size()]);
-            for (final ResultSet element : set) {
-                element.close();
+        final List<AbandonedTrace> resultSetList = getTrace();
+        if (resultSetList != null) {
+            final List<Exception> thrown = new ArrayList<>();
+            final ResultSet[] resultSets = resultSetList.toArray(new 
ResultSet[resultSetList.size()]);
+            for (final ResultSet resultSet : resultSets) {
+                if (resultSet != null) {
+                    try {
+                        resultSet.close();
+                    } catch (Exception e) {
+                        thrown.add(e);
+                    }
+                }
             }
             clearTrace();
+            if (!thrown.isEmpty()) {
+                throw new SQLExceptionList(thrown);
+            }
         }
 
         super.passivate();

Reply via email to