[CONJ-1131] NullPointerException When Calling getGeneratedKeys() Created: 2023-12-05  Updated: 2023-12-05  Resolved: 2023-12-05

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: 3.3.1
Fix Version/s: 3.3.2

Type: Bug Priority: Major
Reporter: Wenqian Deng Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

The bug involves a NullPointerException being thrown when calling the getGeneratedKeys() method on a Statement object after executing an executeBatch() operation in a JDBC application using the MariaDB connector.
This behavior is inconsistent with the MySQL JDBC connector, where no such exception is thrown under similar circumstances, suggesting a potential bug in the MariaDB JDBC connector.
In addition, if I change the first batch SQL to "INSERT INTO table5_0 VALUES(16, -601)", which does not violate the constraint, getGeneratedKeys() will not throw NullPointerException, too.

@Test
public void test() throws SQLException {
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    con = DriverManager.getConnection("jdbc:mariadb://localhost:3366/test5?user=user&password=password");
 
    stmt = con.createStatement();
    stmt.executeUpdate("CREATE TABLE table5_0(id SMALLINT PRIMARY KEY,value BIGINT);");
 
    stmt = con.createStatement();
    stmt.addBatch("INSERT INTO table5_0 VALUES(1679640894, -601)");
    stmt.addBatch("UPDATE table5_0 SET value = 226 WHERE id <= 0");
    try {
        stmt.executeBatch();
    } catch (Exception e) {
        System.out.println(e);
    }
 
    try {
        rs = stmt.getGeneratedKeys(); // java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "this.results" is null
    } catch (Exception e) {
        System.out.println(e);
    }
}


Generated at Thu Feb 08 03:20:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.