Bug #16169 getNativeShort() generates non-terminating recursion
Submitted: 4 Jan 2006 1:10 Modified: 5 Jan 2006 0:17
Reporter: Marten Wensink Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.1.12 + OS:Windows (w2k)
Assigned to: CPU Architecture:Any

[4 Jan 2006 1:10] Marten Wensink
Description:
Type SMALLINT results in a non-terminating recursion in ResultSet.getNativeShort()

How to repeat:
import com.mysql.jdbc.jdbc2.optional.*;
import java.sql.*;

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);

         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 smallint)");
         stmt.executeUpdate ("INSERT INTO test (field1) VALUES (0)");

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

Suggested fix:
?
[4 Jan 2006 19:18] Mark Matthews
I just tried testing this with the latest source for 3.1 and 5.0 (which will be 3.1.13 and 5.0.1 respectively) and could not repeat the bug. 

Could you re-test with either Connector/J 5.0.0 or a nightly snapshot of 3.1 from http://downloads.mysql.com/snapshots.php#connector-j and see if the bug still exists in your environment?
[4 Jan 2006 23:01] Marten Wensink
I repeated the testprogram with the file mysql-connector-java-3.1-nightly-20060104-bin.jar en the following is the output:

Initialize datasource
Setup database connection

Exception in thread "main" java.lang.StackOverflowError
	at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:677)
	at com.mysql.jdbc.ResultSet.getNativeShort(ResultSet.java:7660)
	at com.mysql.jdbc.ResultSet.getNativeShort(ResultSet.java:7687)
	at com.mysql.jdbc.ResultSet.getNativeShort(ResultSet.java:7687)
             ... etc. etc. (about 1000 times)

Unfortunately still an error ???
[5 Jan 2006 0:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/640
[5 Jan 2006 0:17] Mark Matthews
Mea culpa. Didn't pull updates before checking this out (on the road, on laptop).

The fix has been checked into the repository, and should be available in tomorrow's nightly build, or from the subversion repository (immediately) at http://svn.mysql.com/svnpublic/connector-j/branches/branch_3_1

(this was an incomplete backport from 5.0's fix for a different bug).
[5 Jan 2006 0:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/641