[CONJ-200] java.lang.StringIndexOutOfBoundsException: String index out of range: -1 Created: 2015-09-17  Updated: 2015-10-05  Resolved: 2015-09-17

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.2.2
Fix Version/s: 1.3.0

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

The database version isn't relevant since the query is never sent to the db (it fails on the client side)...


Issue Links:
Relates
relates to CONJ-201 Prepared Statement with ? parameters ... Closed

 Description   

There seems to be a regression bug in driver 1.2.2 with the following query that raise an exception (works fine with version 1.2.0):

PreparedStatement ps = c.prepareStatement("insert into t1 (LAST_UPDATE_DATETIME, VERSION) select ?, version from t2");
ps.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
ps.executeUpdate();

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1911)
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)
at com.test.mavenproject5.TestSuite.testMariaDB(TestSuite.java:134)



 Comments   
Comment by Diego Dupin [ 2015-09-17 ]

That has been reproduced, and fixed is done for the next version 1.3.0.

Additionnal test has been done too to avoid this :

 
    @Test
    public void rewriteSelectQuery() throws Throwable {
        Statement st = connection.createStatement();
        st.execute("drop table if exists tselect1");
        st.execute("drop table if exists tselect2");
        st.execute("create table tselect1 (LAST_UPDATE_DATETIME TIMESTAMP , nn int)");
        st.execute("create table tselect2 (nn int)");
        st.execute("INSERT INTO tselect2 VALUES (1)");
        PreparedStatement ps = connection.prepareStatement("/*CLIENT*/ insert into tselect1 (LAST_UPDATE_DATETIME, nn) select ?, nn from tselect2");
        ps.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
        ps.executeUpdate();
 
        ResultSet rs = st.executeQuery("SELECT * FROM tselect1");
        rs.next();
        Assert.assertEquals(rs.getInt(2), 1);
    }
 
    @Test
    public void rewriteSelectQueryServerPrepared() throws Throwable {
        Statement st = connection.createStatement();
        st.execute("drop table if exists tselect1");
        st.execute("drop table if exists tselect2");
        st.execute("create table tselect1 (LAST_UPDATE_DATETIME TIMESTAMP , nn int)");
        st.execute("create table tselect2 (nn int)");
        st.execute("INSERT INTO tselect2 VALUES (1)");
        PreparedStatement ps = connection.prepareStatement("insert into tselect1 (LAST_UPDATE_DATETIME, nn) select ?, nn from tselect2");
        ps.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
        ps.executeUpdate();
 
        ResultSet rs = st.executeQuery("SELECT * FROM tselect1");
        rs.next();
        Assert.assertEquals(rs.getInt(2), 1);
    }

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