commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Nielsen <gl...@voyager.apg.more.net>
Subject Re: [dbcp] bug in DelegatingPreparedStatement
Date Sat, 29 Jun 2002 17:29:52 GMT
Thanks for reporting this.  I had fixed this in the
removeAbandoned() code for abandoned connections.
I'll take care of it.

Regards,

Glenn

Robert Greig wrote:
> 
> 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

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message