Derby
  1. Derby
  2. DERBY-4704

Incorrect nullability when casting non-nullable VARCHAR to BOOLEAN

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.7.1.1
    • Fix Version/s: 10.7.1.1
    • Component/s: SQL
    • Labels:
      None
    • Issue & fix info:
      Patch Available
    • Bug behavior facts:
      Wrong query result

      Description

      With the following table definition and query

      CREATE TABLE T (X VARCHAR(10) NOT NULL);
      INSERT INTO T VALUES 'true', 'false', 'unknown';
      SELECT CAST(X AS BOOLEAN) FROM T;

      the meta-data for the returned result will say that the column is not nullable, although it will contain a NULL value in the third row.

      1. repro.diff
        2 kB
        Knut Anders Hatlen
      2. derby-4704-01-aa-nullability.diff
        4 kB
        Rick Hillegas

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          Thanks for fixing this bug, Rick. Closing the issue.

          Show
          Knut Anders Hatlen added a comment - Thanks for fixing this bug, Rick. Closing the issue.
          Hide
          Rick Hillegas added a comment -

          Tests passed cleanly. Committed at subversion revision 956025.

          Show
          Rick Hillegas added a comment - Tests passed cleanly. Committed at subversion revision 956025.
          Hide
          Rick Hillegas added a comment -

          Attaching derby-4704-01-aa-nullability.diff. This patch forces all casts of strings to booleans to result in nullable types. That is because the string could be "unknown", which casts to NULL. I am running the regression tests now.

          Touches the following files:

          ---------------

          M java/engine/org/apache/derby/impl/sql/compile/CastNode.java

          The actual change.

          ---------------

          M java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java

          Enable Knut's test case.

          Show
          Rick Hillegas added a comment - Attaching derby-4704-01-aa-nullability.diff. This patch forces all casts of strings to booleans to result in nullable types. That is because the string could be "unknown", which casts to NULL. I am running the regression tests now. Touches the following files: --------------- M java/engine/org/apache/derby/impl/sql/compile/CastNode.java The actual change. --------------- M java/testing/org/apache/derbyTesting/functionTests/tests/lang/BooleanValuesTest.java Enable Knut's test case.
          Hide
          Knut Anders Hatlen added a comment -

          Attached is a JUnit test case that reproduces the bug. It is disabled for now, but should be enabled when the bug has been fixed.

          Committed revision 955900.

          Show
          Knut Anders Hatlen added a comment - Attached is a JUnit test case that reproduces the bug. It is disabled for now, but should be enabled when the bug has been fixed. Committed revision 955900.
          Hide
          Knut Anders Hatlen added a comment -

          Marking as "Wrong query result" since the client driver returns the wrong value for unknown (false instead of null) because of this. It also raises an error, but that's not until after it has returned the wrong value.

          ij> SELECT X, CAST(X AS BOOLEAN) FROM T;
          X |2
          ----------------
          true |true
          false |false
          unknown |false
          JAVA ERROR: java.lang.ArrayIndexOutOfBoundsException: 123

          Show
          Knut Anders Hatlen added a comment - Marking as "Wrong query result" since the client driver returns the wrong value for unknown (false instead of null) because of this. It also raises an error, but that's not until after it has returned the wrong value. ij> SELECT X, CAST(X AS BOOLEAN) FROM T; X |2 ---------------- true |true false |false unknown |false JAVA ERROR: java.lang.ArrayIndexOutOfBoundsException: 123

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development