Skip to content

[2.1.214] NulllPointerException in org.h2.command.query.Select.queryDistinct #3664

@nioertel

Description

@nioertel

Hi,

we see the following NPE during simple DISTINCT selects:

Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.NullPointerException"; SQL statement:
SELECT DISTINCT CATEGORY FROM PRODUCT [50000-214]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:554)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
        at org.h2.message.DbException.get(DbException.java:212)
        at org.h2.message.DbException.convert(DbException.java:395)
        at org.h2.command.Command.executeQuery(Command.java:211)
        at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:128)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
        at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:722)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651)
        ... 12 more
Caused by: java.lang.NullPointerException
        at org.h2.command.query.Select.queryDistinct(Select.java:703)
        at org.h2.command.query.Select.queryWithoutCache(Select.java:831)
        at org.h2.command.query.Query.queryWithoutCacheLazyCheck(Query.java:197)
        at org.h2.command.query.Query.query(Query.java:494)
        at org.h2.command.query.Query.query(Query.java:475)
        at org.h2.command.CommandContainer.query(CommandContainer.java:251)
        at org.h2.command.Command.executeQuery(Command.java:190)
        ... 17 more

The query is straight forward as you see above.
The issue only happens if I put LAZY_QUERY_EXECUTION=1; into the connection string.
I think the issue is located in org.h2.command.query.Select#queryWithoutCache, where, if the input target is null, and we have a DISTINCT query and lazy is set to true, result may stay stay null and also to will become null and that's exactly what causes the NPE in queryDistinct.

However we have multiple databases with the same schema and the issue does not occur on all of them. So I believe on top it has something to do with statistics or the actual data other.

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