Uploaded image for project: 'OpenIDM'
  1. OpenIDM
  2. OPENIDM-7014

SQLException thrown during GenericTableHandler.readForUpdate() is masked by failure to close the Statement associated with the ResultSet

    Details

    • Support Ticket IDs:

      Description

      When using MySQL (and likely other DBs), if a SQLException is thrown during a call to GenericTableHandler.readForUpdate() while iterating the ResultSet via calls to next() then the ResultSet is closed within the enclosing try/catch's finally block.

      The above causes an exception within GenericTableHandler.update() method which attempts to close the Statement associated with the ResultSet within the update methods finally block:

              } finally {
                  if (rs != null) {
                          // Ensure associated statement also is closed
                          Statement rsStatement = rs.getStatement();
                      CleanupHelper.loggedClose(rs);
                          CleanupHelper.loggedClose(rsStatement);
                      }
                  CleanupHelper.loggedClose(updateStatement);
                  CleanupHelper.loggedClose(deletePropStatement);
              }
      

      Resulting in the following exception which masks the root-cause of the original failure:

      Caused by: java.sql.SQLException: Operation not allowed on closed ResultSet. Statements can be retained over result set closure by setting the connection property "retainStatementAfterResultSetClose" to "true". 
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078) 
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) 
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) 
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) 
      at com.mysql.jdbc.ResultSetImpl.getStatement(ResultSetImpl.java:5661) 
      at org.forgerock.openidm.repo.jdbc.impl.GenericTableHandler.update(GenericTableHandler.java:714) 
      at org.forgerock.openidm.repo.jdbc.impl.JDBCRepoService.update(JDBCRepoService.java:353) 
      ... 27 more
      

      We need to guard against this by checking not only to see if the ResultSet is non-null but that it is not closed.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                cgdrake Chris Drake
                Reporter:
                cgdrake Chris Drake
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: