Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE when closing cloned JdbcConnection #3402

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

2 participants