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

Prepared Statement with ? parameters after last ) causes string index out of bounds error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.2.3
    • Component/s: Other
    • Labels:
      None
    • Environment:
      MySQL 5.6.22 Community Server
      Win64 x86_64
      java version "1.7.0_71"
      Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

      Description

      Sample Query:

      insert into `SOME_TABLE` (`ID`, `FOO`, `BAR`, `BAZ`) values (?, ?, ?) on duplicate key update `SOME_TABLE`.`FOO` = ?, `SOME_TABLE`.`BAR` = ?, `SOME_TABLE`.`BAZ` = ?

      Problem:

      connection.prepareStatement(sql);

      Throws the following exception:

      Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      	at java.lang.String.substring(Unknown Source)
      	at org.mariadb.jdbc.internal.common.query.MySQLParameterizedQuery.<init>(MySQLParameterizedQuery.java:83)
      	at org.mariadb.jdbc.MySQLPreparedStatement.<init>(MySQLPreparedStatement.java:90)
      	at org.mariadb.jdbc.MySQLConnection.prepareStatement(MySQLConnection.java:181)
      ...

      The problem appears to be on line 83 of MySQLParameterizedQuery:

      rewriteRepeatLastPart = lastPart.substring(0, lastPart.indexOf(")")).getBytes("UTF-8");

      For the above query, the lastPart is an empty string and lastPart.indexOf(")") returns -1, thus lastPart.substring(0,-1) throws an exception.

      I'm not sure what you are trying to do here, so I can't provide a fix but it's definitely a blocker for me.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              diego dupin Diego Dupin
              Reporter:
              mattmadson Matthew Madson
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration