Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-4970

ClassCastException from getBlob() on string parameter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: 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-withTests.diff
        5 kB
        Knut Anders Hatlen
      2. d4970.diff
        2 kB
        Knut Anders Hatlen
      3. Test.java
        0.6 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          knutanders Knut Anders Hatlen added a comment -

          Attaching a repro.

          Show
          knutanders Knut Anders Hatlen added a comment - Attaching a repro.
          Hide
          knutanders 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
          knutanders 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
          knutanders Knut Anders Hatlen added a comment -

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

          Show
          knutanders Knut Anders Hatlen added a comment - Attaching an updated patch which contains a regression test case in jdbcapi.ProcedureTest.
          Hide
          knutanders 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
          knutanders 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
          knutanders Knut Anders Hatlen added a comment -

          All tests ran cleanly on the second try.

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

          Committed revision 1058478.

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

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

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

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development