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

BaseQuery + DataSet doesn't work with default access

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • core-libs
    • b98
    • x86
    • windows_2000
    • Not verified

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b88)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b88, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If you use a class with default access in a @Select query, then it will always return 0 rows, no matter what's in the database. E.g. in:

      interface MyQueries extends BaseQuery {
      @Select("SELECT * FROM address")
      DataSet<Address> getAddresses();
      }

      If Address has anything but public access then getAddresses will always return 0 rows.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See test case source code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Retrieve the rows as usual.
      ACTUAL -
      JUnit version 4.1
      .E.
      Time: 10.986
      There was 1 failure:
      1) rowsExistWithQuery(DataSetTest)
      java.lang.AssertionError: Rows found expected:<1> but was:<0>
             at org.junit.Assert.fail(Assert.java:69)
             at org.junit.Assert.failNotEquals(Assert.java:314)
             at org.junit.Assert.assertEquals(Assert.java:94)
             at DataSetTest.rowsExistWithQuery(DataSetTest.java:61)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:589)
             at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
             at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
             at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
             at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
             at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
             at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
             at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
             at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
             at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
             at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
             at org.junit.internal.runners.CompositeRunner.run(CompositeRunner.java:29)
             at org.junit.runner.JUnitCore.run(JUnitCore.java:121)
             at org.junit.runner.JUnitCore.run(JUnitCore.java:100)
             at org.junit.runner.JUnitCore.run(JUnitCore.java:91)
             at org.junit.runner.JUnitCore.runMain(JUnitCore.java:75)
             at org.junit.runner.JUnitCore.main(JUnitCore.java:42)
             at DataSetTest.main(DataSetTest.java:25)

      FAILURES!!!
      Tests run: 2, Failures: 1



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /* AddressPublic.java (default package) */
      class AddressDefault {
             public int num;
             public String addr;
      }

      public class AddressPublic {
             public int num;
             public String addr;
      }


      /* DataSetTest.java (default package) */
      import java.sql.BaseQuery;
      import java.sql.DataSet;
      import java.sql.Connection;
      import java.sql.Statement;
      import java.sql.SQLException;
      import java.sql.Select;
      import java.sql.DriverManager;
      import java.sql.ResultSet;

      import org.junit.Test;
      import org.junit.Before;
      import org.junit.After;
      import org.junit.runner.JUnitCore;

      import static org.junit.Assert.assertEquals;
      import static org.junit.Assert.assertTrue;
      import static org.junit.Assert.assertFalse;
      import static org.junit.Assert.fail;

      /**
       * Modified from SimpleApp in JavaDB/Derby example source.
       */
      public class DataSetTest
      {

      private interface MyQueries extends BaseQuery {
      @Select("SELECT num, addr FROM address")
      DataSet<AddressDefault> getAllUsersDefault();

      @Select("SELECT num, addr FROM address")
      DataSet<AddressPublic> getAllUsersPublic();
      }


         private Connection conn;

         public static void main(String[] args) {
             JUnitCore.main(DataSetTest.class.getName());
         }

         @Before
         public void createDB() throws Exception {
      Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();

      conn = DriverManager.getConnection("jdbc:derby:derbyDB;create=true");
      conn.setAutoCommit(true);
      Statement s = conn.createStatement();
      s.execute("create table address(num int, addr varchar(40))");
      s.execute("insert into address values (420, 'Enlightment Ln.')");
      s.close();
         }

         @After
         public void shutdownDB() throws Exception {
      Statement s = conn.createStatement();
      s.execute("drop table address");
      s.close();
      if (conn != null) {
      conn.close();
      }
      try {
      DriverManager.getConnection("jdbc:derby:;shutdown=true");
      fail("Database did not shutdown.");
      } catch (SQLException success) {
      }
         }

         @Test
         public void rowsExistWithQueryDefault() throws Exception {
      DataSet<AddressDefault> res = null;
      try {
      MyQueries q = conn.createQueryObject(MyQueries.class);
      res = q.getAllUsersDefault();
      assertEquals("Rows found", 1, res.size());
      assertEquals("Correct num", 420, res.get(0).num);
      assertEquals("Correct addr", "Enlightment Ln.", res.get(0).addr);
      } finally {
      if (res != null) {
      res.close();
      }
      }
         }
         
         @Test
         public void rowsExistWithQueryPublic() throws Exception {
      DataSet<AddressPublic> res = null;
      try {
      MyQueries q = conn.createQueryObject(MyQueries.class);
      res = q.getAllUsersPublic();
      assertEquals("Rows found", 1, res.size());
      assertEquals("Correct num", 420, res.get(0).num);
      assertEquals("Correct addr", "Enlightment Ln.", res.get(0).addr);
      } finally {
      if (res != null) {
      res.close();
      }
      }
         }

         @Test
         public void rowsExistWithStatement() throws Exception {
      Statement s = conn.createStatement();
      ResultSet rs = s.executeQuery("SELECT num, addr FROM address");
      assertTrue("Rows found", rs.next());
      assertEquals("Correct num", 420, rs.getInt(1));
      assertEquals("Correct addr", "Enlightment Ln.", rs.getString(2));
      assertFalse("Only one row", rs.next());
      rs.close();
      s.close();
         }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Make the class public access.

            ssharmasunw Sushmita Sharma (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: