Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 400523

Summary: Invalid Resource Leak Warning Reported for void Method; Adding Empty Return Resolves Warning
Product: [Eclipse Project] JDT Reporter: Shea Tomsin <shea>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED DUPLICATE QA Contact:
Severity: minor    
Priority: P3 CC: jarthana, stephan.herrmann
Version: 4.2   
Target Milestone: 4.3 M2   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/155060
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=785c7ca7509cb0eb9aef1b5862a374ffd0b0a5d7
Whiteboard:
Attachments:
Description Flags
IDE Editor none

Description Shea Tomsin CLA 2013-02-12 01:27:55 EST
Created attachment 226896 [details]
IDE Editor

void method flagged with 'potential resource leak' warnings (see setValue) but adding an empty return (see setValueReturn) satisfies IDE.

Appears related to bug 383779 but that bug involves a for loop example and has a comment 'removing the for loop from my sample makes the warning go away'.  There is no loop in this example.

Appears related to bug 360910 but that bug involves re-throwing the exceptions; this example sinks exceptions.

I apologize in advance for submitting a duplicate bug should this be determined a duplicate.

----------------------------------

package com;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LeakWarning {
	String value = null;
	
    public void setValue(Connection conn)
	{        
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {            
            stmt = conn.prepareStatement("SELECT 'value'");  /* marked as potential resource leak */
            rs = stmt.executeQuery();                        /* marked as potential resource leak */
            if (rs.next()) value = rs.getString(1);
        } catch(SQLException e) {
        }
        finally {
        	if (null != rs)   try { rs.close();   } catch (SQLException e) {} finally { rs = null;   }
        	if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }
        }
    }
    
    public void setValueReturn(Connection conn)
	{        
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {            
            stmt = conn.prepareStatement("SELECT 'value'");
            rs = stmt.executeQuery();
            if (rs.next()) value = rs.getString(1);
        } catch(SQLException e) {
        }
        finally {
        	if (null != rs)   try { rs.close();   } catch (SQLException e) {} finally { rs = null;   }
        	if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }
        }
        return; /* no warning now */
    }
}
Comment 1 Eclipse Genie CLA 2019-11-23 06:55:41 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Stephan Herrmann CLA 2019-11-23 08:07:04 EST
To be investigated in the next round of bug fixes in this area.
Comment 3 Stephan Herrmann CLA 2019-12-26 16:20:47 EST
This was actually fixed in 4.3 M2, I'm taking an educated guess at which change may have fixed it.

*** This bug has been marked as a duplicate of bug 388996 ***
Comment 4 Eclipse Genie CLA 2019-12-26 16:23:36 EST
New Gerrit change created: https://git.eclipse.org/r/155060
Comment 5 Stephan Herrmann CLA 2019-12-27 03:47:22 EST
(In reply to Eclipse Genie from comment #4)
> New Gerrit change created: https://git.eclipse.org/r/155060

Regression test released for 4.15 M1