Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6375277

DataSet.sync(conn) with connection=true throws a NPE.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • None
    • b68
    • 6
    • b95
    • generic
    • generic
    • Verified

      DataSet.sync(conn) with connection=true throws a NPE, it should throw a SQLRuntimeException which same as using DataSet.sync().

      JDK : 1.6.0-b68
      DB : ORCL
      VM : default
      switch/Mode : default
      Platform[s] : Sol 10 sparc tested.

      Test owner :
      Failing Test :
          java_sql_eod/dataset/DataSet002_004

      TestBase Location:
      ==================

          /net/cady.sfbay/export/sqa/tcheung/jdbc/SQE/6.0

      Test source location:
      =====================
          /net/cady.sfbay/export/sqa/tcheung/jdbc/SQE/6.0/jdbc/src/java_sql_eod/dataset/DataSet002_004

      Share source location:
      ======================
         /net/cady/export/sqa/tcheung/jdbc/SQE/6.0/jdbc/share
         /net/cady/export/sqa/tcheung/jdbc/SQE/6.0/share


      How to reproduce:
      ====================
      cd /net/cady/export/sqa/tcheung/jdbc/BUGS/[bug id]
      change the DB's IP,username and passwd
      javac QueryTest.java
      java QueryTest
         

      --------Sample Test/Script START---------------------
      QueryTest.java

      import java.sql.*;

      public class QueryTest {
          
          Connection conn = null;
          Connection conn1 = null;
          Statement stmt = null;

          
          private void doSetup() {
              try {
                  Class.forName("com.inet.ora.OraDriver");
              }catch (ClassNotFoundException ex) {
                  System.err.println("Exception when loading JDBC driver : "+ex);
              }
       
              try {
                  conn = DriverManager.getConnection("jdbc:inetora:IP:1521:ORCL", "user", "pwd");
                  conn1 = DriverManager.getConnection("jdbc:inetora:IP:1521:ORCL", "user", "pwd");
                  stmt = conn.createStatement();
                  stmt.executeUpdate("drop table query001");
              }catch (SQLException ex) {
                  System.err.println("Exception : "+ex);
              }
              
               try {
                  stmt.addBatch("create table query001 ( id number, firstName varchar2(32), lastName varchar2(32), primary key (id))");
                  stmt.addBatch("insert into query001 values ( 1, 'fname1', 'last_name1')");
                  stmt.addBatch("insert into query001 values ( 2, 'fname2', 'last_name2')");
                  stmt.executeBatch();
              }catch (SQLException ex) {
                  System.err.println("Exception when executing SQL :"+ex);
              }
          }
          
          private void doTest() {
              
              DataSet<PersonDO> rows = null;
              I_Query001 query = null;
              
              try {
                  query = QueryObjectFactory.createQueryObject(I_Query001.class, conn1);
              } catch (SQLException sqlEx) {
                  System.err.println("SQLException caught "+sqlEx.getMessage());
              }

              System.out.println("Calling query.getAllPersons() ...");
              rows = query.getAllPersons();
              System.out.println("DataSet.size="+rows.size());

              for(PersonDO p : rows) {
      System.out.println("Id: "+p.id+" First Name: "+p.firstName+" Last Name: "+p.lastName);
      if( p.id == 1)
      {
                   rows.delete();
                 }
      }
      try
      {
      rows.sync(conn);
      } catch(SQLDataSetSyncException spe) {
      System.out.println("Caught : "+spe.getMessage());
      DataSetResolver<ConflictingRow> ds = spe.getDataSetResolver();
      for(ConflictingRow cr : ds) {
      PersonDO pd = (PersonDO)cr.getRow();
      System.out.println("pd id: "+pd.id);
      System.out.println("pd firstName: "+pd.firstName);
      System.out.println("pd lastName: "+pd.lastName);

      //pd.firstName = "thiiswrong";
                     //pd.firstName = "syncproblemFirst";
      }
      ds.sync();
      }
       
          }
          public static void main(String[] args) {
              QueryTest qtest = new QueryTest();
              qtest.doSetup();
              qtest.doTest();
          }
      }

      interface I_Query001 extends BaseQuery {
          //@Select(sql="SELECT id , firstName, lastName from query001",connected=false,tableName="query001",readOnly=false)
          @Select(sql="SELECT id , firstName, lastName from query001",connected=true,readOnly=false)
          DataSet<PersonDO> getAllPersons() ;

      }

      --------------------------------
      PersonDo.java


      import java.sql.ResultColumn;

      public class PersonDO {
          //@ResultColumn(uniqueIdentifier=true)public long id ;
          public long id ;
          public String firstName ;
          public String lastName ;
      }




      --------Sample Test/Script END----------------------

      Test output:
      =====
      java -version
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b68)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b68, mixed mode)
      orthello>javac QueryTest.java
      Note: QueryTest.java uses unchecked or unsafe operations.
      Note: Recompile with -Xlint:unchecked for details.
      orthello>java QueryTest
      Calling query.getAllPersons() ...
      DataSet.size=2
      Id: 1 First Name: fname1 Last Name: last_name1
      Id: 2 First Name: fname2 Last Name: last_name2
      Exception in thread "main" java.lang.NullPointerException
              at com.sun.sql.DataSetImpl.asRowSet(DataSetImpl.java:425)
              at com.sun.sql.DataSetImpl.sync(DataSetImpl.java:1270)
              at QueryTest.doTest(QueryTest.java:60)
              at QueryTest.main(QueryTest.java:80)
      ========

      Specific Machine Info:
      =====================
      For Solaris[sparc/x86] ->
      SunOS orthello 5.10 Generic sun4u sparc SUNW,Ultra-60

            ssharmasunw Sushmita Sharma (Inactive)
            tacheung Tak Wing Cheung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: