impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
596 stars 108 forks source link

NullPointerException on Calling getMoreResults #593

Open dwenking opened 8 months ago

dwenking commented 8 months ago

The bug manifests as an unexpected NullPointerException when invoking the getMoreResults method. In the provided test case, after executing a batch insert into a table and retrieving the generated keys using getGeneratedKeys(), the method getMoreResults(Statement.KEEP_CURRENT_RESULT) is called on the Statement object. This call unexpectedly results in a NullPointerException. The stack trace indicates that the exception is due to an attempt to invoke isEmpty() on a null object (this.resultBatches).

@Test
public void test() throws SQLException {
    Connection con;
    Statement stmt;
    ResultSet rs ;
    con = DriverManager.getConnection("jdbc:pgsql://localhost:5432/test5?user=user&password=password");
    stmt = con.createStatement();
    stmt.execute("CREATE TABLE table5_0(id FLOAT PRIMARY KEY,value VARCHAR(100));");
    stmt.addBatch("INSERT INTO table5_0 VALUES(1, 'SeXM.j;.xbN5tXkzPPY')");
    stmt.executeBatch();
    rs = stmt.getGeneratedKeys();
    stmt.getMoreResults(Statement.KEEP_CURRENT_RESULT); // java.lang.NullPointerException: Cannot invoke "java.util.List.isEmpty()" because "this.resultBatches" is null
    rs.close();
    con.close();
}