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

Bug 369849

Summary: Avoid resource leak warning when the underlying/chained resource is closed explicitly - Part 2
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, stephan.herrmann, the.ubik
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Deepak Azad CLA 2012-01-26 13:33:42 EST
Similar to bug 360908.

Potential resource leak: 'reader' may not be closed	WorkbenchSWTActivator.java	/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt	line 246

Notice the 2 levels of wrapping, which is not too uncommon. I think 3 levels of wrapping is also possible but may not be that common. I assume the analysis only takes care of only 1 level of wrapping? I would expect similar limitation in solution of bug 361073 and other places.
-----------------------------------------------------------------------------
InputStream is = null;
try {
	is = dsURL.openStream();
	BufferedReader reader = new BufferedReader(new InputStreamReader(
			is, "utf-8")); //$NON-NLS-1$  //warning
	dialogSettings.load(reader);
} catch (IOException e) {
	// load failed so ensure we have an empty settings
	dialogSettings = new DialogSettings("Workbench"); //$NON-NLS-1$
} finally {
	try {
		if (is != null) {
			is.close();  // underlying resource closed here
		}
	} catch (IOException e) {
		// do nothing
	}
}
-----------------------------------------------------------------------------
Comment 1 Stephan Herrmann CLA 2012-01-26 13:53:19 EST
(In reply to comment #0)
> Similar to bug 360908.
> 
> Potential resource leak: 'reader' may not be closed   
> WorkbenchSWTActivator.java   
> /org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt  
>  line 246
> 
> Notice the 2 levels of wrapping, which is not too uncommon. I think 3 levels of
> wrapping is also possible but may not be that common. I assume the analysis
> only takes care of only 1 level of wrapping?

"Unfortunately", no, the analysis can cope with any level of wrapping.
Unfortunate, because that means there's got to be some bug involved.

From looking at the snippet one theory is:
- is is closed iff (is != null)
- we already correlate nullness and closedness to conclude that if its
  null it cannot be unclosed
- however, there's no way we can correlate the nullness of is with the closedness of reader.

So either this, or another bug in the context of bug 368546 (nested try statements have been involved in some false positives before).
Comment 2 Palmer Eldritch CLA 2013-07-18 18:26:43 EDT
Would this :

public static void readFiletoArrayList(String fileName, String charsetName) {
	try {
		InputStream file = new FileInputStream(fileName);
		try {
			InputStreamReader reader = new InputStreamReader(file,
					charsetName);
			BufferedReader buffer = new BufferedReader(reader);
			// ^^^^^^^ Resource leak: 'buffer' is never closed
			buffer.read();
		} finally {
			file.close();
		}
	} catch (IOException e) {}
}

fall to the same bug ?
Comment 3 Eclipse Genie CLA 2019-09-15 19:08:32 EDT
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.