Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-81

[dbcp] NPE in PoolableConnectionFactory validating the connection with an invalid SQL statement

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.2
    • None
    • None
    • Operating System: All
      Platform: All

    • 36685

    Description

      The PooleableConnectionFactory.validateConnection(Connection) throws a NPE, if
      the provided SQL statement for validation is invalid itself (e.g. uses a
      non-existing table). See the code snippet below. If stmt.executeQuery(query)
      throws an SQLException, rset is still null, but will be closed in the finally
      block ==> NPE!

      if(null != query) {
      Statement stmt = null;
      ResultSet rset = null;
      try {
      stmt = conn.createStatement();
      rset = stmt.executeQuery(query);
      if(!rset.next())

      { throw new SQLException("validationQuery didn't return a row"); }

      } finally {
      try

      { rset.close(); }

      catch(Exception t)

      { // ignored }
      try { stmt.close(); } catch(Exception t) { // ignored }

      }
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            joehni Joerg Schaible
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: