Derby
  1. Derby
  2. DERBY-4970

ClassCastException from getBlob() on string parameter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.7.1.1
    • Fix Version/s: 10.8.1.2
    • Component/s: JDBC
    • Labels:
      None
    • Issue & fix info:
      Repro attached

      Description

      If you call getBlob() on a string parameter in a CallableStatement, you'll get a ClassCastException. We should get a proper SQLException.

      Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Blob
      at org.apache.derby.impl.jdbc.EmbedCallableStatement.getBlob(EmbedCallableStatement.java:580)
      at Test.main(Test.java:13)

      1. d4970.diff
        2 kB
        Knut Anders Hatlen
      2. d4970-withTests.diff
        5 kB
        Knut Anders Hatlen
      3. Test.java
        0.6 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          Attaching a repro.

          Show
          Knut Anders Hatlen added a comment - Attaching a repro.
          Hide
          Knut Anders Hatlen added a comment -

          The attached patch makes getBlob() and getClob() in EmbedCallableStatement throw a proper error when there's a type mismatch. The exception in the repro is changed from

          java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Blob

          to

          java.sql.SQLDataException: An attempt was made to get a data value of type 'java.sql.Blob' from a data value of type 'VARCHAR'.

          I haven't run any tests or added a regression test case yet.

          Show
          Knut Anders Hatlen added a comment - The attached patch makes getBlob() and getClob() in EmbedCallableStatement throw a proper error when there's a type mismatch. The exception in the repro is changed from java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Blob to java.sql.SQLDataException: An attempt was made to get a data value of type 'java.sql.Blob' from a data value of type 'VARCHAR'. I haven't run any tests or added a regression test case yet.
          Hide
          Knut Anders Hatlen added a comment -

          Attaching an updated patch which contains a regression test case in jdbcapi.ProcedureTest.

          Show
          Knut Anders Hatlen added a comment - Attaching an updated patch which contains a regression test case in jdbcapi.ProcedureTest.
          Hide
          Knut Anders Hatlen added a comment -

          I got one failure in suites.All when I ran the tests, a network server failed to start. It's probably not related to the patch, but I'll rerun the tests just in case. Setting the patch available flag.

          Show
          Knut Anders Hatlen added a comment - I got one failure in suites.All when I ran the tests, a network server failed to start. It's probably not related to the patch, but I'll rerun the tests just in case. Setting the patch available flag.
          Hide
          Knut Anders Hatlen added a comment -

          All tests ran cleanly on the second try.

          Show
          Knut Anders Hatlen added a comment - All tests ran cleanly on the second try.
          Hide
          Knut Anders Hatlen added a comment -

          Committed revision 1058478.

          Show
          Knut Anders Hatlen added a comment - Committed revision 1058478.
          Hide
          Dag H. Wanvik added a comment -

          Looks good to me. Verified that test fails without the fix. +1

          Show
          Dag H. Wanvik added a comment - Looks good to me. Verified that test fails without the fix. +1

            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