NullpointerException

47 views
Skip to first unread message

Mike Bray

unread,
Jul 11, 2020, 1:09:42 PM7/11/20
to H2 Database
I have an app that creates a database if not present by copying a blank database, running a set of create table statements and then running a set of inserts to add the data.  This has been running successfully for about a year using build 1.4.198.  I have recently upgraded to 1.4.200 and I get a nullpointerexception with a JdbcSQLNonTransientException.  The log is:

org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.NullPointerException" [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.server.TcpServerThread.sendError(TcpServerThread.java:234)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:185)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
at org.h2.command.dml.TableValueConstructor.isEverything(TableValueConstructor.java:262)
at org.h2.command.dml.Query.collectDependencies(Query.java:935)
at org.h2.command.CommandList.getDependencies(CommandList.java:123)
at org.h2.engine.Session.startStatementWithinTransaction(Session.java:1819)
at org.h2.command.Command.executeUpdate(Command.java:245)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:406)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:183)
... 1 more

at org.h2.message.DbException.getJdbcSQLException(DbException.java:505)
at org.h2.engine.SessionRemote.done(SessionRemote.java:611)
at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:237)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:228)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201)
at application.DatabaseManager.createDatabase(DatabaseManager.java:153)
at application.Main.start(Main.java:35)

Is this a known issue?
Has a change in builds 199 or 200 caused this?

Any help would be appreciated

Evgenij Ryazanov

unread,
Jul 11, 2020, 10:37:15 PM7/11/20
to H2 Database
Hello.

It looks like you're trying to execute multiple commands at once and you have a table value constructor after some data definition command:

try (Connection c = DriverManager.getConnection("jdbc:h2:mem:1")) {
    c
.createStatement().execute("CREATE TABLE TEST(); VALUES 1");
}

H2 returns result only from the first command, others are executed, but their results aren't returned, so such combination of commands has very low meaning.

Anyway, there was a bug in H2. It should be fixed in current H2. You can build H2 from the current sources to test it.

Mike Bray

unread,
Jul 12, 2020, 3:23:49 AM7/12/20
to H2 Database
Thank you for the quick reply.  I can quite believe there are errors in my SQL which build 198 did not find but build 200 does.

I tried following the instructions to download and build h2 using Eclipse.  When Eclipse built the project it came up with 2 errors both in h2.util:

Bits.java  the 'public final class Bits' had 'The type Bits is already defined'
NetUtils2.java 'public final class NetUtils2' had 'The type NetUtils2 is already defined'

Anyway I ran 'build jar' and it completed successfully.

On test it threw out some of my SQL with a syntax error. I was going to use the console to try out the statements to find the error but the .jar built does not have the tools within it so I can not run the console with the new build.  

Am I missing something.

Evgenij Ryazanov

unread,
Jul 12, 2020, 4:35:44 AM7/12/20
to H2 Database
build.cmd jar (or ./build.sh jar on Linux, OS X, etc.) in h2 subdirectory produces jar file with exactly the same content as included into official releases in bin/h2-***.jar. It has H2 Console and command-line Shell tool, so I don't understand what do you mean by tools.

You need Java 8, 9, 10, 11, or 12. Build script isn't compatible with newer versions (but H2 supports them too).

If you want to compile H2 in Eclipse, add only h2/src/main as a source directory. You can also add h2/src/test and h2/src/tools, if you need to run unit tests or some other code. Don't add other directories as source directories. But for you there is no reason to use Eclipse for compilation of H2.

Mike Bray

unread,
Jul 12, 2020, 4:54:50 AM7/12/20
to H2 Database
OK thanks. I have subsequently downloaded the 200 build and installed it. As far as compiling with Eclipse, I followed the instructions for cloning the code and creating a project within Eclipse.  It showed the 2 errors.  The console complained about could not find 'org.h2.tools.console' hence my comment.  It now now works with the jar I built.

Reading up after your comment about multiple statements in one string  I have also rewritten my code to split my sql files up into individual SQL statements and used executeBatch() to run them.  This now works on build 200.

Thanks for your time.
Reply all
Reply to author
Forward
0 new messages