commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Greig <>
Subject [dbcp] bug in DelegatingPreparedStatement
Date Fri, 28 Jun 2002 19:44:49 GMT

I was using the latest build of the dbcp classes and I found a bug in 
the DelegatingPreparedStatement.

Basically, using the class will almost guarantee you get a 
ConcurrentModificationException from the trace list.

I think this problem was introduced in the commit:

revision 1.4
date: 2002/06/28 15:28:20;  author: glenn;  state: Exp;  lines: +19 -20
Fix a memory leak when tracing abandoned connections.
Cleanup of passivate and close methods.

The problem is the close() method of DelegatingPreparedStatement (and 
presumably others). Here are the problem lines:

List resultSets = getTrace();
if( resultSets != null) {
     Iterator it = resultSets.iterator();
     while(it.hasNext()) {
        ((ResultSet);  // Line 166 of the source file

The problem is that the elements in the iterator are really 
DelegatingResultSets which try to remove themselves from their container 
when close() is called on them. Hence the List which you're iterating 
through is modified during iteration.

The solution is obviously simple - just copy the list first, e.g.

ResultSet[] set = new ResultSet[resultSets.size()];
for (int i = 0; i < set.length; i++) {


Best regards,

Robert Greig

View raw message