Skip to content

Commit

Permalink
Fix for Bug#104753 (Bug#33286177), PreparedStatement.setFetchSize(0) …
Browse files Browse the repository at this point in the history
…causes ArrayIndexOutOfBoundsException.

Change-Id: I41c9c326cfa853bd01ac499e927bf223f12ffe28
  • Loading branch information
fjssilva committed Jun 29, 2022
1 parent 146ebf2 commit edce7a5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.31

- Fix for Bug#104753 (Bug#33286177), PreparedStatement.setFetchSize(0) causes ArrayIndexOutOfBoundsException.

Version 8.0.30

- Fix for Bug#107510 (Bug#34259416), Empty string given to set() from Collection.modify() replaces full document.
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12539,4 +12539,69 @@ public void testBug76623() throws Exception {
testConn.close();
} while (useSPS = !useSPS);
}

/**
* Tests fix for Bug#104753 (Bug#33286177), PreparedStatement.setFetchSize(0) causes ArrayIndexOutOfBoundsException.
*
* @throws Exception
*/
@Test
public void testBug104753() throws Exception {
createTable("testBug104753", "(id BIGINT NOT NULL, PRIMARY KEY (id))");

Consumer<Integer> runQuery = (f) -> { // fetchSize
try {
this.pstmt.setFetchSize(f);
this.pstmt.execute();
this.rs = this.pstmt.getResultSet();
assertTrue(this.rs.next());
assertEquals(1, this.rs.getInt(1));
} catch (Throwable e) {
fail("Exception not expected");
}
};

this.stmt.executeUpdate("INSERT INTO testBug104753 VALUES (1)");

Properties props = new Properties();
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "true");
props.setProperty(PropertyKey.useCursorFetch.getKeyName(), "true");

// With prepared statements cache, COM_STMT_RESET sent.
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);

this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(0);
this.pstmt.close();
this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(1);
this.pstmt.close();
this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(0);
this.pstmt.close();
this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(0);
this.pstmt.close();
this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(1);
this.pstmt.close();

testConn.close();

// No prepared statements cache, no COM_STMT_RESET sent.
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), "false");
testConn = getConnectionWithProps(props);

this.pstmt = testConn.prepareStatement("SELECT id FROM testBug104753");
runQuery.accept(0);
runQuery.accept(1);
runQuery.accept(0);
runQuery.accept(0);
runQuery.accept(1);

testConn.close();
}
}

0 comments on commit edce7a5

Please sign in to comment.