Bug #58444 NullPointerException in com.mysql.jdbc.StatementImpl.closeAllOpenResults
Submitted: 24 Nov 2010 7:30 Modified: 25 Mar 2013 12:26
Reporter: Mikiya Okuno Email Updates:
Status: Can't repeat Impact on me:
Category:Connector / J Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[24 Nov 2010 7:30] Mikiya Okuno
Since com.mysql.jdbc.StatementImpl.realClose isn't thread-safe, it causes NullPointerException when called from multiple threads at a time.

realClose returns if isClosed member is false. But, isClosed member isn't protected by any lock, so multiple threads can go through logics to close the target Statement at the same time. If one thread set openResults = null, then other thread may cause NullPointerException in closeAllOpenResults method.

How to repeat:
Call Statement#close simultaneously on Statement instance which has not been closed yet.

Suggested fix:
Synchronize isClosed member.
[24 Nov 2010 15:10] Mark Matthews
Is there a legitimate reason to share a statement between threads? While this could be made thread-safe, it would be at the expense of slowing down the 99% of use cases that don't use a questionable usage pattern.
[25 Mar 2013 12:26] Alexander Soklakov
Hi Mikiya,

I was not able to reproduce this failure with latest C/J, so I close this report as "Can't repeat". But feel free to reopen if you find that the problem still exists.