Bug #97757 NullPointerException with cacheResultSetMetadata=true and executeQuery of "set"
Submitted: 24 Nov 2019 6:34 Modified: 27 Mar 18:27
Reporter: Edmon Luan Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.18 OS:Debian
Assigned to: CPU Architecture:x86

[24 Nov 2019 6:34] Edmon Luan
Description:
MySQL Server version: 10.3.18-MariaDB-0+deb10u1 Debian 10

Java:
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode)

With cacheResultSetMetadata=true, calling Statement.executeQuery("set ...") throws NullPointerException. The set statement can be anything like "set autocommit=0" for example.

With cacheResultSetMetadata=false, Statement.executeQuery("set ...") returns a ResultSet normally.

How to repeat:
Run the following:

Connection c = DriverManager.getConnection(
  "jdbc:mysql://localhost:3306/mysql?sslMode=DISABLED&cacheResultSetMetadata=true&user=..."
);
Statement s = c.createStatement();
s.executeQuery("set autocommit = 0"); // throws NullPointerException

Suggested fix:
Statement.executeQuery("set ...") should behave consistently no matter of cacheResultSetMetadata
[24 Nov 2019 6:38] Edmon Luan
Simplified reproduction

Attachment: MySQLCJ8Issue.java (text/x-java), 726 bytes.

[24 Nov 2019 6:42] Edmon Luan
stack trace

Attachment: trace (application/octet-stream, text), 594 bytes.

[24 Nov 2019 8:34] MySQL Verification Team
Hello Edmon Luan,

Thank you for the report and test case.

regards,
Umesh
[27 Mar 18:27] Daniel So
Posted by developer:
 
Added the following entry to the C/J 8.0.20 changelog: 

"A NullPointerException was returned when the connection had cacheResultSetMetadata=true and a query containing any set statements was executed. This fix corrects the issue by adding the missing variable assignment, and also a null check."