Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6493779

Using JdbcRowSetImpl(strUrl,strUserId, strPassword) without executing a stmt throws NPE in getType()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6u1
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b01
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        It appears that at line 2097 in JdbcRowSetImpl.java (which I think is int rstype = rs.getType()) a NPE is thrown even though I setType() for JdbcRowSetImpl to ResultSet.TYPE_FORWARD_ONLY. This is because when using the constructor JdbcRowSetImpl(strUrl,strUserId, strPassword) without executing a statement, ResultSet is null and its type is also null. So calling getType(), even though it was set before throws NPE.

        TEST SRC SNIPPET:

        111 jrs1 = new JdbcRowSetImpl(strUrl,strUserId, strPassword);
        112 jrs1.setType(ResultSet.TYPE_FORWARD_ONLY);
        113 logMsg("Type set to: "+ ResultSet.TYPE_FORWARD_ONLY);
        114
        115 logMsg("Type is: "+ResultSet.TYPE_FORWARD_ONLY);
        116
        117 if(jrs1.getType() == ResultSet.TYPE_FORWARD_ONLY) {
        118 logMsg("Test for Type passes...");
        119 } else {
        120 logMsg("Test for Type fails...");
        121 throw new TestFailureException("JdbcRowSet test fails");
        122 }
        123 } catch (SQLException sqle) {
        124 logErr("SQL Exception encountered " + sqle.getMessage());
        125 throw new TestFailureException("JdbcRowSet Test failed", sqle);
        126 } catch (Exception e) {
        127 logErr("Unexpected Exception " + e.getMessage());
        128 throw new TestFailureException("JdbcRowSet Test failed", e);
        129 }


        SRC SNIPPET:

            /**
             *
             * Returns the fetch size for this
             * <code>ResultSet</code> object.
             *
             * @return the current fetch size for this rowset's <code>ResultSet</code> object
             * @throws SQLException if a database access error occurs
             * or this rowset does not currently have a valid connection,
             * prepared statement, and result set
             */
            public int getType() throws SQLException {
                try {
                     checkState();
                } catch(SQLException sqle) {
                    return super.getType();
                }
                try {
                    int rstype = rs.getType();
                    return rstype;
                } catch(NullPointerException npe) {
                     throw new SQLException("Cannot return the type of a closed ResultSet : " + npe);
                }

            }

        OUTPUT:

        [2006-11-14T18:37:11.58] SQL Exception encountered Cannot return the type of a closed ResultSet : java.lang.NullPointerException
        [2006-11-14T18:37:12.48] Error: JdbcRowset2_012 : JdbcRowSet Test failed
        [2006-11-14T18:37:12.48] com.sun.j2se_sqe.jdbc.utils.TestFailureException: JdbcRowSet Test failed
        [2006-11-14T18:37:12.48] at JdbcRowset2_012.doTest(JdbcRowset2_012.java:125)
        [2006-11-14T18:37:12.48] at JdbcRowset2_012.main(JdbcRowset2_012.java:183)
        [2006-11-14T18:37:12.48] Caused by: java.sql.SQLException: Cannot return the type of a closed ResultSet : java.lang.NullPointerException
        [2006-11-14T18:37:12.48] at com.sun.rowset.JdbcRowSetImpl.getType(JdbcRowSetImpl.java:2097)
        [2006-11-14T18:37:12.48] at JdbcRowset2_012.doTest(JdbcRowset2_012.java:117)
        [2006-11-14T18:37:12.48] ... 1 more
        [2006-11-14T18:37:12.48] # Test level exit status: 1
        [2006-11-14T18:37:12.48] PropertyReader: SQL_DIR_PATH=/home/sandeepk/workspace/7.0/jdbc/4.0_tests/workDir
        [2006-11-14T18:37:12.48] PropertyReader: SQL_FILE_NAME=initdb.conf
        [2006-11-14T18:37:12.48] PropertyReader: SQL_ABS_PATH=/home/sandeepk/workspace/7.0/jdbc/4.0_tests/workDir/initdb.conf
        [2006-11-14T18:37:12.48] Loading the driver class com.inet.ora.OraDriver
        [2006-11-14T18:37:12.48] Loading the driver class com.inet.ora.OraDriver
        [2006-11-14T18:37:12.48] Starting the test...
        [2006-11-14T18:37:12.48] Getting a new Jdbc RowSet
        [2006-11-14T18:37:12.48] Coammand is: Select * from CRS_Objects
        [2006-11-14T18:37:12.48] Type set to: 1003
        [2006-11-14T18:37:12.48] Type is: 1003

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  lancea Lance Andersen
                  Reporter:
                  skonchad Sandeep Konchady
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: