Bug #75691 Resource is not closed in NonRegisteringDriver
Submitted: 30 Jan 2015 6:20 Modified: 5 Feb 2015 16:23
Reporter: Shou Aoki Email Updates:
Status: Verified Impact on me:
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.34 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[30 Jan 2015 6:20] Shou Aoki
Hi all, We found resource leak on com.mysql.jdbc.NonRegisteringDriver#parseURL. 

That code is following:

    try {
        InputStream configAsStream = super.getClass().getResourceAsStream(
                "configs/" + configName + ".properties");
    } catch (IOException ioEx) {

The variable configAsSystem is not closed.
However getResourceAsStream() is use FileInputStream, This class will call close method by *finalize method*.
So configAsStream will close when GC run but we want close immediately after load properties.

How to repeat:
When you use the "useConfigs" property.

Suggested fix:
Use try-with-resources with configAsStream variable.
[5 Feb 2015 16:23] Filipe Silva

Thank you for this bug report. It was verified as described.