Description:
com.mysql.jdbc.ChannelBuffer.java's readString method tries to set the buffer position past the limit at this line:
final String readString() {
int len = 0;
int maxLen = getBufLength();
int oldPosition = getPosition();
while ((getPosition() < maxLen) && (this.directBuffer.get() != 0)) {
len++;
}
setPosition(oldPosition);
String s = new String(bufferToArray(), getPosition(), len);
>>> this.directBuffer.position(getPosition() + len + 1); // update cursor
causing an IllegalArgumentException to be thrown from Sun's nio Buffer class:
public final Buffer position(int newPosition) {
if ((newPosition > limit) || (newPosition < 0))
>>> throw new IllegalArgumentException();
In my case, it was trying to set position 11 and limit was 10.
Here is the head of the stack trace:
java.sql.SQLException: General error: java.lang.IllegalArgumentException
at com.mysql.jdbc.MysqlIO.buildResultSetWithUpdates(MysqlIO.java:2045)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1939)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1384)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1133)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:670)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1159)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1076)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1061)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
How to repeat:
here is the url form I am using:
jdbc:mysql://${sql.host}/${sql.database}?autoReconnectForPools=true&prepStmtCacheSize=100&cachePrepStmts=true&elideSetAutoCommits=true&useLocalSessionState=true&useNewIO=true
if I change to this, the error goes away:
jdbc:mysql://${sql.host}/${sql.database}?autoReconnectForPools=true&prepStmtCacheSize=100&cachePrepStmts=true&elideSetAutoCommits=true&useLocalSessionState=true
I am using an auto-increment column and the preparedstatement uses Statement.RETURN_GENERATED_KEYS in this particular case, not sure if that matters. It fails whether doing an insert of a blank row (insert into foo () values();) just to get the next id, and when inserting a row with some values set. This is failing on 10 different tables.
Java 1.5.0_05
MySql running on Windows XP, version 4.1.10-nt-log