NPE when running query with timestamp conversion in 1.4.200

62 views
Skip to first unread message

pwagland

unread,
Nov 1, 2020, 6:44:50 PM11/1/20
to H2 Database
Hi all,

We are trying to upgrade from H2 1.3.153 to 1.4.200, and are running into the following NPE:

org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.NullPointerException"; SQL statement:
select time_value, formatdatetime(time_value, 'HH:mm:ss.SSS') from JDBCHelperTest where test_name = ? [50000-200]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:505)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
at org.h2.message.DbException.get(DbException.java:194)
at org.h2.message.DbException.convert(DbException.java:347)
at org.h2.command.Command.executeQuery(Command.java:212)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:114)
at com.xxx.JDBCHelperTest.checkTime(JDBCHelperTest.java:428)
at com.xxx.JDBCHelperTest.testBindByPosition_Time(JDBCHelperTest.java:1272)
     <snip the boring bits of junit>
Caused by: java.lang.NullPointerException
at org.h2.value.Value.convertToTimestamp(Value.java:1146)
at org.h2.value.Value.convertTo(Value.java:822)
at org.h2.value.Value.convertTo(Value.java:737)
at org.h2.value.Value.getTimestamp(Value.java:591)
at org.h2.expression.function.Function.getValueWithArgs(Function.java:1530)
at org.h2.expression.function.Function.getValue(Function.java:672)
at org.h2.command.dml.Select$LazyResultQueryFlat.fetchNextRow(Select.java:1851)
at org.h2.result.LazyResult.hasNext(LazyResult.java:101)
at org.h2.result.LazyResult.next(LazyResult.java:60)
at org.h2.command.dml.Select.queryFlat(Select.java:737)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:844)
at org.h2.command.dml.Query.queryWithoutCacheLazyCheck(Query.java:201)
at org.h2.command.dml.Query.query(Query.java:489)
at org.h2.command.dml.Query.query(Query.java:451)
at org.h2.command.CommandContainer.query(CommandContainer.java:285)
at org.h2.command.Command.executeQuery(Command.java:195)
... 25 more

As far as I can tell, this would still fail on current master as well, it's a little more difficult to test there though, as there are no pre-built binaries that I could find…

However, what happens is that `Value.getTimesstamp(TimeZone)` calls `Value. convertTo(Value.TIMESTAMP))`, which in turn calls `Value.convertTo(targetType, nullnullfalsenull)`.  That third null, is `CastDataProvider provider`. This provider is `null`, however when it is passed to `Value.convertToTimestamp(provider, forComparison)`, that method assumes that provider, isn't null, and thus we get the NPE.

The SQL that we are passing in can be seen in the stack trace. I can't see anything wrong with the query, nor can I see any obvious workaround. I am hoping that someone here will be able to help me see what we have done wrong, and how we can fix it without needing to wait for 2.0.202.

Cheers,
Paul

pwagland

unread,
Nov 1, 2020, 9:13:44 PM11/1/20
to H2 Database
I can also now confirm that this was introduced in 1.4.200, when I downgrade to 1.4.199, this test works as expected.

Cheers,
Paul

Evgenij Ryazanov

unread,
Nov 2, 2020, 7:01:25 AM11/2/20
to H2 Database
Hello.

Yes, it's a known regression, it was found after release of 1.4.200 and was fixed in development sources, but, unfortunately, a patch release was not published in time.

You can cast the passed value to a TIMESTAMP explicitly as a workaround, or you can compile H2 from the sources by yourself.

pwagland

unread,
Nov 2, 2020, 9:02:41 AM11/2/20
to H2 Database
Thanks! Yes, that cast worked perfectly… now to see if there is anything none test related that is broken :-)
Reply all
Reply to author
Forward
0 new messages