1. OpenJPA
  2. OPENJPA-415

Garbage collection of AbstractResultList instance closes active connection


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.1, 1.1.0
    • Fix Version/s: 1.0.1, 1.1.0
    • Component/s: jdbc
    • Labels:


      While investigation a problem, I noticed that garbage collection kicks in on the AbstractResultList's finalize() method.
      at org.apache.openjpa.lib.jdbc.DelegatingConnection.close(
      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.close(
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection.close(
      at org.apache.openjpa.jdbc.sql.ResultSetResult.close(
      at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.close(
      at org.apache.openjpa.lib.rop.WindowResultList.close(
      at org.apache.openjpa.lib.rop.AbstractResultList.finalize(
      at java.lang.J9VMInternals.runFinalize(

      When traversing the call stack to the ResultSetResult.close() method, it is trying to close the result set unconditionally, and then close the associated statement and connection if they exists:

      public void close() {

      { _rs.close(); }

      catch (SQLException se) {
      if (_stmnt != null)

      { _stmnt.close(); }

      catch (SQLException se) {
      if (_closeConn)

      { _conn.close(); }

      catch (SQLException se) {

      Would this be a undesired side-effect and a problem in the following scenario:

      1) appl / openjpa obtains a connection
      2) create a prepare statement
      3) get a result set from the statement
      4) using the same statement and get another result set. The first result set is not being referenced by any code and ready for gc.
      5) the connection and statement is active for a long time and gc kicks in to gc the first result set instance
      6) eventually the ResultSetResult.close() gets call.
      7) The statement and connection gets closed while it is still being used by appl / openjpa.

      Is this a possible scenario?

      According to the JCA architecture, connection that is scoped to a transaction will be closed by the connection manager and all associated statements and result set managed by the connection will be automatically closed. So is the AbstractResultList.finalize() ever be needed at all?

      Albert Lee.


        Albert Lee made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Albert Lee made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.1.0 [ 12312344 ]
        Fix Version/s 1.0.1 [ 12312687 ]
        Resolution Fixed [ 1 ]
        Albert Lee made changes -
        Attachment OPENJPA-415.patch [ 12368320 ]
        Albert Lee made changes -
        Field Original Value New Value
        Assignee Albert Lee [ allee8285 ]
        Albert Lee created issue -


          • Assignee:
            Albert Lee
            Albert Lee
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: