Skip to content

NPE in ConditionNot.getNotIfPossible() #2804

@mrigger

Description

@mrigger

Consider the following test case:

CREATE TABLE t0(c0 INT);
SELECT * FROM t0 WHERE NOT NOT - C0; -- General error: "java.lang.NullPointerException" [50000-200] HY000/50000

Unexpectedly, this causes a NullPointerException in H2 with the following stacktrace:

Caused by: java.lang.NullPointerException
    at org.h2.expression.condition.Condition.castToBoolean(Condition.java:27)
    at org.h2.expression.condition.ConditionNot.getNotIfPossible(ConditionNot.java:31)
    at org.h2.expression.condition.ConditionNot.optimize(ConditionNot.java:50)
    at org.h2.expression.Expression.optimizeCondition(Expression.java:150)
    at org.h2.command.query.Select.prepare(Select.java:1177)
    at org.h2.command.Parser.prepareCommand(Parser.java:948)
    at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:630)
    at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:568)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1139)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:221)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:207)

If the predicate is invalid, I would expect that a more descriptive error is returned. I found this based on commit 59fb36c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions