8000 Fix NPE when closing cloned JdbcConnection by ThePrez · Pull Request #3402 · h2database/h2database · GitHub
[go: up one dir, main page]

Skip to content

Conversation

ThePrez
Copy link
@ThePrez ThePrez commented Jan 24, 2022

closing a cloned JdbcConnection (by calling the copy constructor) results in an NPE:

org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.NullPointerException" [50000-210]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:573)
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
	at org.h2.message.DbException.get(DbException.java:216)
	at org.h2.message.DbException.convert(DbException.java:414)
	at org.h2.message.DbException.toSQLException(DbException.java:386)
	at org.h2.message.TraceObject.logAndConvert(TraceObject.java:365)
	at org.h2.jdbc.JdbcConnection.close(JdbcConnection.java:368)
Caused by: java.lang.NullPointerException
	at org.h2.util.CloseWatcher.unregister(CloseWatcher.java:100)
	at org.h2.jdbc.JdbcConnection.close(JdbcConnection.java:334)
	... 2 more

This is because the clone nulls out the watcher field of the cloned object, which I believe is by design:

Circumvented with a simple null check which I propose as a small fix.

@grandinj
Copy link
Contributor

do you have a test case for this?

@ThePrez ThePrez marked this pull request as draft January 24, 2022 22:02
@ThePrez
Copy link
Author
ThePrez commented Jan 24, 2022

I can certainly make one. I'll put this in draft status until I add a test to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0