Author: markt
Date: Sun Jun 21 16:41:18 2009
New Revision: 787049

URL: http://svn.apache.org/viewvc?rev=787049&view=rev
Log:
Fix DBCP-288. When passivating a DelegatingConnection, not all of the trace 
objects will be statements so check each one before casting and closing.
Based on a patch provided by Marc Kannegießer

Modified:
    
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java

Modified: 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java?rev=787049&r1=787048&r2=787049&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
 (original)
+++ 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
 Sun Jun 21 16:41:18 2009
@@ -24,6 +24,7 @@
 import java.sql.SQLException;
 import java.sql.SQLWarning;
 import java.sql.Statement;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 /* JDBC_4_ANT_KEY_BEGIN */
@@ -410,12 +411,15 @@
         try {
             // The JDBC spec requires that a Connection close any open
             // Statement's when it is closed.
-            List statements = getTrace();
-            if( statements != null) {
-                Statement[] set = new Statement[statements.size()];
-                statements.toArray(set);
-                for (int i = 0; i < set.length; i++) {
-                    set[i].close();
+            // POOL-288. Not all the traced objects will be statements
+            List traces = getTrace();
+            if(traces != null) {
+                Iterator traceIter = traces.iterator();
+                while (traceIter.hasNext()) {
+                    Object trace = traceIter.next();
+                    if (trace instanceof Statement) {
+                        ((Statement) trace).close();
+                    }
                 }
                 clearTrace();
             }


Reply via email to