Bug 359362

Summary: FUP of bug 349326: Resource leak on non-Closeable resource.
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: deepakazad, srikanth_sankaran
Version: 3.8   
Target Milestone: 3.8 M3   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
proposed fix
none
enhanced fix none

Description Ayushman Jain CLA 2011-09-29 04:19:15 EDT
Due to thw fix for bug 349326, the following two tests fail:

1)test0147(org.eclipse.jdt.core.tests.dom.ASTConverter15Test)
junit.framework.ComparisonFailure: different output.
----------- Expected ------------

------------ but was ------------
Resource leak: 'next' is never closed


2) test0147(org.eclipse.jdt.core.tests.dom.ASTConverter15JLS4Test)
junit.framework.ComparisonFailure: different output.
----------- Expected ------------

------------ but was ------------
Resource leak: 'next' is never closed


Test snippet is as follows
import java.lang.Comparable;
import java.util.Collection;
import java.util.Iterator;

public class X {
	public static <T extends Object & Comparable<? super T>> T min(
			Collection<? extends T> coll) {
		Iterator<? extends T> i = coll.iterator();
		T candidate = i.next();

		while (i.hasNext()) {
			T next = i.next();
			if (next.compareTo(candidate) < 0)
				candidate = next;
		}
		return candidate;
	}
}
Comment 1 Ayushman Jain CLA 2011-09-29 04:20:15 EDT
In the snippet, 'T' is not a resource of type 'Closeable', yet we get the warning.

Stephan, can you take a look? Thanks!
Comment 2 Ayushman Jain CLA 2011-09-29 04:55:12 EDT
Created attachment 204267 [details]
proposed fix

Stephan, can you check if this fix is ok? The tests pass with this. Thanks!
Comment 3 Stephan Herrmann CLA 2011-09-29 08:24:04 EDT
Created attachment 204285 [details]
enhanced fix

(In reply to comment #2)
> Created attachment 204267 [details]
> proposed fix
> 
> Stephan, can you check if this fix is ok? The tests pass with this. Thanks!

The location and idea of your fix is perfect.
The underlying issue is that super types of a type variable may have their
typeBits still uninitialized at this point. Thus we were passing -1 (marking
state uninitialized) down.

Rather than filtering out -1 in the end my patch ensures that all super
types properly initialized their typeBits before merging bits.
For this purpose I changed -1 for uninitialized to an explicit new bit:
TypeIds.BitUninitialized.

I also changed the corresponding method for WildcardBinding, yet I 
wouldn't know how to create a test for this, as concrete expressions
should never have the type of a wildcard, but rather a capture binding.

Also included in this patch: I added close() calls to the class VerifyTests
(string constant in TestVerifier) to avoid the new warning in the console
output of compiler tests.

I'm currently re-running the model tests.
Comment 4 Stephan Herrmann CLA 2011-09-29 09:05:16 EDT
Tests pass with the enhanced fix.

Released as commit 247dd2da1a649afa18a4b7387fd9cbdf69c251eb for 3.8 M3.
Comment 5 Ayushman Jain CLA 2011-09-29 09:08:14 EDT
(In reply to comment #3)
Thanks Stephan! For fixing this and the VerifyTests issue. I noticed it recently and was going to fix it :)
Comment 6 Srikanth Sankaran CLA 2011-10-24 20:50:13 EDT
Verified for 3.8 M3 using build id: N20111022-2000