Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-839

Wrong exception message when rewriteBatchedStatements is enabled

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 2.6.2, 2.7.0
    • 2.7.1
    • batch
    • 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.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            echipachenko Yevhen Chypachenko
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.