Bug #3723 throw StringIndexOutOfBoundsException when use GBK
Submitted: 12 May 2004 12:15 Modified: 28 Mar 2014 10:35
Reporter: Zanxiong Liu Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.0.11, 3.1.1, ... OS:Windows (Windows)
Assigned to: Mark Matthews CPU Architecture:Any

[12 May 2004 12:15] Zanxiong Liu
Description:
Use Connector/J 3.0.11 or 3.1.1 connect MySQL 4.0.18, if MySQL default character set is GBK or set characterEncoding=GBK, if the streaming data has Chinese, the JDBC Driver will throw StringIndexOutOfBoundsException, like this:

SQLException: Error during query: Unexpected Exception: java.lang.StringIndexOutOfBoundsException me ssage given: String index out of range: 38

Nested Stack Trace:
** BEGIN NESTED EXCEPTION **
java.lang.StringIndexOutOfBoundsException
MESSAGE: String index out of range: 38

STACKTRACE:

java.lang.StringIndexOutOfBoundsException: String index out of range: 38
        at java.lang.String.charAt(String.java:444)
        at com.mysql.jdbc.StringUtils.escapeSJISByteStream(StringUtils.java:280)
        at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:105)
        at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:74)
        at com.mysql.jdbc.Buffer.writeStringNoNull(Buffer.java:502)
        at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1150)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2087)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2037)
        at com.mysql.jdbc.Statement.execute(Statement.java:900)
        at com.neusoft.test.MySqlJdbcTest.main(MySqlJdbcTest.java:34)
** END NESTED EXCEPTION **

SQLState: S1000

If use Connector/J 3.0.8, it's OK.

How to repeat:
see Description.

Suggested fix:
fix com.mysql.jdbc.StringUtils.escapeSJISByteStream()
[12 May 2004 13:41] Mark Matthews
Please try a nightly build of 3.0 or 3.1, as these have wide charset fixes in them.

See http://downloads.mysql.com/snapshots.php
[12 May 2004 16:16] Zanxiong Liu
3.0 and 3.1 20040511 nightly build is OK.
[28 Mar 2014 10:35] Alexander Soklakov
Fixed in 3.0.12 and 3.1.2