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

    • Bug
    • Status: Closed (View Workflow)
    • Blocker
    • Resolution: Fixed
    • 1.2.2
    • 1.2.3
    • Other
    • None
    • 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

              diego dupin Diego Dupin
              mattmadson Matthew Madson
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.