ITADN

NullPointerException on Calling getMoreResults

#593Opendwenking 创建于 2023-11-16
D
dwenkingcommented
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). ```java @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(); } ```
0 条评论