DatabaseMetadata: NPE hides exception in finally block

Description

There a is problem when an exception occurs in org.hibernate.tool.hbm2ddl.DatabaseMetadata#initSequences:

If rs = statement.executeQuery(sql) fails, then in finally block we try to invoke close() method on rs object, which is still null. According to JLS §14.20.2.:

If the finally block completes abruptly for reason S, then the try statement completes abruptly for reason S (and the throw of value V is discarded and forgotten).

So the reason why statement.executeQuery(sql) failed is discarded and forgotten and NullPointerException is thrown. That makes it really hard to debug.

I found this bug when I in my Spring application I've tried to connect do DERBY database using H2Dialect:

Environment

None

Activity

Show:
Mateusz Sulima
April 20, 2014, 12:37 PM

Assignee

Brett Meyer

Reporter

Mateusz Sulima

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

backportDecision

None

Components

Affects versions

Priority

Trivial
Configure