Derby
  1. Derby
  2. DERBY-4964

Client driver fails to convert string to boolean with setObject(col, str, Types.BIT)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.7.1.1
    • Fix Version/s: 10.7.1.4, 10.8.1.2
    • Component/s: JDBC
    • Labels:
      None
    • Issue & fix info:
      Repro attached
    • Bug behavior facts:
      Deviation from standard, Embedded/Client difference

      Description

      The following code

      PreparedStatement ps = c.prepareStatement("values cast(? as boolean)");
      ps.setObject(1, "true", Types.BIT);
      ResultSet rs = ps.executeQuery();
      rs.next();
      System.out.println(rs.getString(1));

      executes successfully using the embedded driver, but fails when using the client driver:

      Exception in thread "main" java.sql.SQLDataException: Invalid character string format for type INTEGER.
      at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
      at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
      at org.apache.derby.client.am.PreparedStatement.setObject(Unknown Source)
      at Test.main(Test.java:8)
      Caused by: org.apache.derby.client.am.SqlException: Invalid character string format for type INTEGER.
      at org.apache.derby.client.am.CrossConverters.setObject(Unknown Source)
      at org.apache.derby.client.am.CrossConverters.setObject(Unknown Source)
      at org.apache.derby.client.am.PreparedStatement.setObjectX(Unknown Source)
      ... 2 more
      Caused by: java.lang.NumberFormatException: For input string: "true"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Integer.parseInt(Integer.java:449)
      at java.lang.Integer.valueOf(Integer.java:554)
      ... 5 more

      This issue was found when running the Java EE CTS with Derby 10.7.1.1.

      1. mapping-test.diff
        4 kB
        Knut Anders Hatlen
      2. derby-4964-1a.diff
        14 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          3d 17h 46m 1 Knut Anders Hatlen 14/Jan/11 15:33
          In Progress In Progress Closed Closed
          3d 1h 20m 1 Knut Anders Hatlen 17/Jan/11 16:53
          Gavin made changes -
          Workflow jira [ 12542079 ] Default workflow, editable Closed status [ 12797090 ]
          Knut Anders Hatlen made changes -
          Link This issue is related to DERBY-5788 [ DERBY-5788 ]
          Rick Hillegas made changes -
          Fix Version/s 10.8.1.2 [ 12316362 ]
          Fix Version/s 10.8.1.1 [ 12316356 ]
          Rick Hillegas made changes -
          Fix Version/s 10.8.1.1 [ 12316356 ]
          Fix Version/s 10.8.1.0 [ 12315561 ]
          Knut Anders Hatlen made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Fix Version/s 10.7.1.3 [ 12315902 ]
          Resolution Fixed [ 1 ]
          Hide
          Knut Anders Hatlen added a comment -

          Merged to 10.7 and committed revision 1059984.

          Show
          Knut Anders Hatlen added a comment - Merged to 10.7 and committed revision 1059984.
          Knut Anders Hatlen made changes -
          Fix Version/s 10.8.0.0 [ 12315561 ]
          Issue & fix info [Repro attached, Patch Available] [Repro attached]
          Hide
          Knut Anders Hatlen added a comment -

          Committed revision 1059888.

          Show
          Knut Anders Hatlen added a comment - Committed revision 1059888.
          Knut Anders Hatlen made changes -
          Issue & fix info [Repro attached] [Patch Available, Repro attached]
          Knut Anders Hatlen made changes -
          Attachment derby-4964-1a.diff [ 12468380 ]
          Hide
          Knut Anders Hatlen added a comment -

          Attaching a patch to fix this bug. This patch contains more tests. All the new test cases pass with no changes needed when run against the embedded driver. With the fix applied, they also pass when run against the client driver.

          ParameterMappingTest.java: Add testing of setObject(int,Object,int) for all types (same as mapping-test.diff).

          BooleanValuesTest.java: Add more specific tests for boolean with a wider range of input values.

          CrossConverters.java: Add separate cases for converting to boolean and stop handling boolean conversions as integer conversions.

          Types.java: Add handling of Types.BIT, so that error messages say "BOOLEAN" instead of "<UNKNOWN>" when attempting invalid conversions like setObject(col, "test", Types.BIT).

          All the regression tests ran cleanly with the patch.

          Show
          Knut Anders Hatlen added a comment - Attaching a patch to fix this bug. This patch contains more tests. All the new test cases pass with no changes needed when run against the embedded driver. With the fix applied, they also pass when run against the client driver. ParameterMappingTest.java: Add testing of setObject(int,Object,int) for all types (same as mapping-test.diff). BooleanValuesTest.java: Add more specific tests for boolean with a wider range of input values. CrossConverters.java: Add separate cases for converting to boolean and stop handling boolean conversions as integer conversions. Types.java: Add handling of Types.BIT, so that error messages say "BOOLEAN" instead of "<UNKNOWN>" when attempting invalid conversions like setObject(col, "test", Types.BIT). All the regression tests ran cleanly with the patch.
          Knut Anders Hatlen made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Knut Anders Hatlen made changes -
          Attachment mapping-test.diff [ 12468250 ]
          Hide
          Knut Anders Hatlen added a comment -

          Attaching a patch that makes ParameterMappingTest expose the bug. ParameterMappingTest only tested setObject(int,Object) before. The patch adds testing of setObject(int,Object,int), which is where the problem is seen. The test passes with the embedded driver and fails on the client driver when the patch is applied.

          Show
          Knut Anders Hatlen added a comment - Attaching a patch that makes ParameterMappingTest expose the bug. ParameterMappingTest only tested setObject(int,Object) before. The patch adds testing of setObject(int,Object,int), which is where the problem is seen. The test passes with the embedded driver and fails on the client driver when the patch is applied.
          Knut Anders Hatlen made changes -
          Field Original Value New Value
          Assignee Knut Anders Hatlen [ knutanders ]
          Hide
          Knut Anders Hatlen added a comment -

          We have the same problem if Types.BIT is replaced with Types.BOOLEAN.

          Show
          Knut Anders Hatlen added a comment - We have the same problem if Types.BIT is replaced with Types.BOOLEAN.
          Knut Anders Hatlen created issue -

            People

            • Assignee:
              Knut Anders Hatlen
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development