Bug #58728 com.mysql.jdbc.jdbc2.optional.StatementWrapper.getResultSet()
Submitted: 4 Dec 2010 7:46 Modified: 6 Dec 2010 13:42
Reporter: Dain Sundstrom Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.13 OS:Any
Assigned to: CPU Architecture:Any

[4 Dec 2010 7:46] Dain Sundstrom
Description:
com.mysql.jdbc.jdbc2.optional.StatementWrappe.getResultSet() will throw a NullPointerException if wrappedStmt.getResultSet() returns null.  According to the javadocs java.sql.Statement.getResultSet() method will return null "if the result is an update count or there are no more results", and mysql correctly returns null from update statements.

How to repeat:
Using a MysqlConnectionPoolDataSource Execute an INSERT, UPDATE or DELETE and then call getResultSet on the statement,

Suggested fix:
Put a simple if not null statement around call to setWrapperStatement(this) in getResultSet.  Something like this:

if (rs != null)
    ((com.mysql.jdbc.ResultSetInternalMethods) rs).setWrapperStatement(this);
}
[6 Dec 2010 13:28] Tonci Grgin
Hi Dain and thanks for your report.

Verified just as described with following test case:
	createTable("testbug58728", "(Id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, txt VARCHAR(50))","InnoDB");
	this.stmt.executeUpdate("INSERT INTO testbug58728 VALUES (NULL, 'Text 1'), (NULL, 'Text 2')");
		
	MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
	pds.setUrl(dbUrl);
	Statement stmt1 = pds.getPooledConnection().getConnection().createStatement();
	stmt1.executeUpdate("UPDATE testbug58728 SET txt = 'New text' WHERE Id > 0");
	ResultSet rs1 = stmt1.getResultSet();
	stmt1.close();
	if (rs1 != null) {
		rs1.close();
	}
[6 Dec 2010 13:42] Tonci Grgin
Pushed up to revision 1025.