[CONJ-839] Wrong exception message when rewriteBatchedStatements is enabled Created: 2020-11-12  Updated: 2020-11-17  Resolved: 2020-11-17

Status: Closed
Project: MariaDB Connector/J
Component/s: batch
Affects Version/s: 2.6.2, 2.7.0
Fix Version/s: 2.7.1

Type: Bug Priority: Major
Reporter: Yevhen Chypachenko Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

10.2.31-MariaDB-log
JDBC 2.6.2
Java 8


Attachments: PNG File Screenshot at 18-36-32.png    

 Description   

Steps to reproduce

1. Create a connection with enabled rewriteBatchedStatements=true
2. Use the following code to reproduce the issue:

        Connection con = DriverManager.getConnection("jdbc:mariadb://localhost:3306/test?rewriteBatchedStatements=true");
        PreparedStatement pstmt = con.prepareStatement("UPDATE table1 SET col1 = ?, col2 = 0 WHERE col3 = ?;");
        pstmt.setInt(1, 10);
        pstmt.setInt(2, 20);
        pstmt.addBatch();
        pstmt.setInt(1, 100);
        pstmt.setInt(2, 200);
        pstmt.executeBatch();

Expected result

For any error we are expecting valid message, for example: java.sql.BatchUpdateException: (conn=86322) Table 'test.table1' doesn't exist

Actual result

Some unexpected message appears: java.sql.BatchUpdateException: (conn=86341) Error reading results 2

Additional details

I made some analysis and found that this unexpected messae is coming from the class org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol#executeBatchMulti method handleResultException and it cause ArrayIndexOutOfBoundException when it tries to build error message. See attached screenshot, with explanation, why there's ArrayIndexOutOfBoundException. For some reasons paramCount was defined as 4, but actually query has only 2 parameters.
NOTE: When I remove the last semicolon in the query - it is working as expected.



 Comments   
Comment by Diego Dupin [ 2020-11-17 ]

corrected with commit
https://github.com/mariadb-corporation/mariadb-connector-j/commit/70bdf81b61ffbb23f1d240be1ef913e164f95af3

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