| Bug #64 | ResultSet.first() throws Null Pointer Exception | ||
|---|---|---|---|
| Submitted: | 11 Feb 2003 6:52 | Modified: | 11 Feb 2003 7:27 |
| Reporter: | [ name withheld ] | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S3 (Non-critical) |
| Version: | 3.0.5 Gamma | OS: | Linux (Red Hat 8.0) |
| Assigned to: | CPU Architecture: | Any | |
[11 Feb 2003 7:27]
Mark Matthews
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at http://www.mysql.com/downloads/ This was actually fixed a couple of days ago. It's in the nightly snapshots at http://mmmysql.sourceforge.net/snapshots/ or you can wait for 3.0.6 to be released. Basically, the ResultSet should be closed when you issue another query (as per the JDBC spec). The ResultSet implementation for Connector/J does this (which cleans up some object instances, and then sets them to 'null'), but didn't subsequently check in traversal methods whether or not the ResultSet was closed, thus leading to the NullPointerException.

Description: When tying multiple ResultSets to a single Statement object, if both ResultSets have no rows then executing ResultSet.first() throws a Null Pointer exception. Stack Trace: - com.mysql.jdbc.ResultSet: first: 2288 - MySqlCode: testMethod: xyz How to repeat: Either one of the rsn.first() calls below will throw an exception. CREATE TABLE Table1 ( Column1 INT ) TYPE=INNODB; CREATE TABLE Table2 ( Column1 INT ) TYPE=INNODB; { Statement myStatement = myConnection.createStatement(); ResultSet rs1 = null; ResultSet rs2 = null; rs1 = myStatement.executeQuery( "SELECT * FROM Table1" ); rs2 = myStatement.executeQuery( "SELECT * FROM Table2" ); if (rs1.first()) { System.out.println( "Found a record in Table1" ); } if (rs2.first()) { System.out.println( "Found a record in Table2" ); } } Suggested fix: One possible "kludgey" fix is to modify ResultSet line 2288 from if (rowData.isEmpty()) { Change it to: if (rowData == null || rowData.isEmpty()) { However, this may not be the optimal solution. Since I don't really know the code I cannot really give a decent suggestion.