commons-dev mailing list archives

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

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)it.next()).close();  // Line 166 of the source file
     }
     clearTrace();
}

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()];
resultSets.toArray(set);
for (int i = 0; i < set.length; i++) {
     set[i].close();
}

etc.

Best regards,

Robert Greig

Mime
View raw message