"Impossible" StringIndexOutOfBoundsException - race condition?
Brought to you by:
ickzon
I received the following stacktrace while getting the next result from a result set.
java.lang.StringIndexOutOfBoundsException: String index out of range: -182
at java.lang.String.checkBounds(String.java:381)
at java.lang.String.<init>(String.java:425)
at net.sourceforge.jtds.jdbc.ResponseStream.readString(ResponseStream.java:304)
at net.sourceforge.jtds.jdbc.ResponseStream.readNonUnicodeString(ResponseStream.java:285)
at net.sourceforge.jtds.jdbc.TdsData.readData(TdsData.java:961)
at net.sourceforge.jtds.jdbc.TdsCore.tdsRowToken(TdsCore.java:3175)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2433)
at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:805)
at net.sourceforge.jtds.jdbc.JtdsResultSet.next(JtdsResultSet.java:611)
The error is not reproducible, and the way I read the code, it shouldn't even be "possible" (scare quotes)..
TdsData.readData shouldn't be able to call ResonseStream.readNonUnicodeString with len -182.
I suspect the cause may be a race condition with two threads accessing the same connection from the connection pool.
We are using jTDS 1.3.1 with Tomcat DBCP 8.0.23.
I am aware that this is not really enough information to reproduce the problem or fix it, but I thought I'd post it anyway in case anyone else has a similar issue.
Sorry, forgot to include the Java version.
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)