Bug #11563 ArrayIndexOutOfBoundsException
Submitted: 25 Jun 2005 11:05 Modified: 27 Jun 2005 12:24
Reporter: M Wensink Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10 OS:Microsoft Windows (w2k)
Assigned to: CPU Architecture:Any

[25 Jun 2005 11:05] M Wensink
Description:
Connector/J throws a very strange exception when using useNewIO flag.

public class Test {

   private static final String server   = "localhost";
   private static final String database = "test";
   private static final String username = "root";
   private static final String password = "root";

   private Statement stmt;

   public static void main (String [ ] args)
   {
      try
      {  System.err.println ("Initialize datasource");
         MysqlDataSource ds = new MysqlDataSource();
         ds.setServerName (server);
         ds.setDatabaseName (database);
         ds.setUser (username);
         ds.setPassword (password);
         ds.setUseNewIo (true);

         System.err.println ("Setup database connection\n");
         Connection conn = ds.getConnection();

         test (conn);
      }
      catch (Exception e)
      {  e.printStackTrace (System.err);
         System.exit (1);
      }
   }

   private static void test (Connection conn) throws Exception
   {
      Statement stmt = conn.createStatement();
      try {
         stmt.executeUpdate ("DROP TABLE IF EXISTS test");
         stmt.executeUpdate ("CREATE TABLE test (field1 integer, field2 integer)");
         stmt.executeUpdate ("INSERT INTO test (field1,field2) VALUES (NULL,NULL)");

         PreparedStatement ps = conn.prepareStatement ("SELECT * FROM test");
         ResultSet rs = ps.executeQuery();
      	if (rs.next())
      	{	Integer i = (Integer) rs.getObject ("field1");
            System.out.println ("field1: " + i);
            i = (Integer) rs.getObject ("field2");
            System.out.println ("field2: " + i + "\n");
	      }
			ps.close();
      }
      finally {
         stmt.executeUpdate ("DROP TABLE IF EXISTS test");
      }
   }
}

The exception is not thrown when the second NUL-value in the INSERT-statement is replace by e.g. 0 or when the ps.close() is left out or when the finally-statement is left out.

How to repeat:
Use the above test program

Suggested fix:
?
[25 Jun 2005 13:58] Vasily Kishkin
Could you please say what version of mysqld you use ? I tested on 4.1.13 and 5.0.8. I got the follow result:

Initialize datasource
Setup database connection

field1: null
field2: null

I wonder why fields are null. But I did't see any exception.
[25 Jun 2005 17:33] M Wensink
I'm using server 4.1.12.

Of course the null-values are strange, but I simplified the statement as part of a bigger statement in which null-values can happen.

Marten
[25 Jun 2005 20:14] Aleksey Kishkin
test case

Attachment: bug11563.java (application/octet-stream, text), 1.79 KiB.

[25 Jun 2005 20:14] Aleksey Kishkin
tested and got:
Initialize datasource
Setup database connection

java.sql.SQLException: Error during query: Unexpected Exception: java.lang.ArrayIndexOutOfBoundsException message given: null

Nested Stack Trace:

** BEGIN NESTED EXCEPTION ** 

java.lang.ArrayIndexOutOfBoundsException

STACKTRACE:

java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at com.mysql.jdbc.ChannelBuffer.getBytes(ChannelBuffer.java:178)
	at com.mysql.jdbc.ChannelBuffer.readLenByteArray(ChannelBuffer.java:321)
	at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1303)
	at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2258)
	at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:421)
	at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:1959)
	at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1384)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1727)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:929)
	at bug11563.test(bug11563.java:56)
	at bug11563.main(bug11563.java:29)

** END NESTED EXCEPTION **

	at com.mysql.jdbc.Connection.execSQL(Connection.java:3025)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
	at com.mysql.jdbc.Statement.executeUpdate(Statement.java:929)
	at bug11563.test(bug11563.java:56)
	at bug11563.main(bug11563.java:29)
[25 Jun 2005 21:47] M Wensink
Yes, that's the one.
[25 Jun 2005 21:50] Mark Matthews
We're considering deprecating the use of newIO because it doesn't seem to be a performance win, and some implementations of it are buggy.

Do you _really_ need to use it? This is the only outstanding bug filed against it, and if it turns out to be related to newIO implementation, or is a large engineering effort to fix it, we have to weigh the fix against the fact that the feature is most likely going away in Connector/J 3.2.
[26 Jun 2005 10:04] M Wensink
No, I do not need the feature. I found the error while experimenting with some features to speed up the system. I also discovered another major bug (double insertions in the database), so I decided not to use the useNewIO option.

Thanks.
[27 Jun 2005 12:24] Aleksey Kishkin
OK, in that case I seal it as 'wont'fix' and deprecated