Details
- 
    Bug 
- 
    Status: Closed (View Workflow)
- 
    Major 
- 
    Resolution: Fixed
- 
    2.6.2, 2.7.0
- 
    None
- 
    10.2.31-MariaDB-log
 JDBC 2.6.2
 Java 8
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. 
