Bug 363293 - resource leaks in org.eclipse.jdt.compiler.tool.tests
Summary: resource leaks in org.eclipse.jdt.compiler.tool.tests
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 07:05 EST by Stephan Herrmann CLA
Modified: 2011-12-06 06:48 EST (History)
3 users (show)

See Also:


Attachments
proposed patch (5.03 KB, patch)
2011-11-09 07:12 EST, Stephan Herrmann CLA
no flags Details | Diff
patch with sorting (5.85 KB, patch)
2011-11-09 09:44 EST, Stephan Herrmann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2011-11-09 07:05:16 EST
When compiled using 3.8M3 the test suite org.eclipse.jdt.compiler.tool.tests 
raises 8 warnings like "Resource leak: 'fileManager' is never closed".

It seems that all these warnings are justified and should be fixed in the code.
Comment 1 Stephan Herrmann CLA 2011-11-09 07:12:07 EST
Created attachment 206678 [details]
proposed patch

This patch resolves the warnings by adding appropriate close() calls.

When I run the tests in the IDE I get one failure, though:
org.eclipse.jdt.compiler.tool.tests.CompilerToolTests.testFileManager2():
  
   Expected: "X2.javaX.java" but got "X.javaX2.java".

A simple ordering issue, not sure if this is a known issue 
and this is independent of my patch anyway.
Comment 2 Ayushman Jain CLA 2011-11-09 07:53:52 EST
(In reply to comment #1)
Thats strange. Adding close calls seems to have changed the ordering of CU's in the fileManager. May be worth investigating why this happened, just to be sure there's no auxilliary problem that arose because of the new close() call.
Comment 3 Stephan Herrmann CLA 2011-11-09 08:04:40 EST
(In reply to comment #2)
> (In reply to comment #1)
> Thats strange. Adding close calls seems to have changed the ordering of CU's in
> the fileManager. May be worth investigating why this happened, just to be sure
> there's no auxilliary problem that arose because of the new close() call.

I tried to mention that I see this failure also without the added close calls.

BTW: the doc of JavaFileManager.list(..) doesn't seem to make any
guarantees regarding the order in the result.
Comment 4 Ayushman Jain CLA 2011-11-09 08:25:27 EST
(In reply to comment #3)
> I tried to mention that I see this failure also without the added close calls.
Ah! I see. I applied your patch and ran the test. Passes on my machine (Win32) everytime.Maybe on linux it gives an incorrect ordering sometimes. So, unless you see the incorrect order everytime you run the test, I guess the patch should be good.
Comment 5 Stephan Herrmann CLA 2011-11-09 09:17:34 EST
(In reply to comment #4)
> (In reply to comment #3)
> > I tried to mention that I see this failure also without the added close calls.
> Ah! I see. I applied your patch and ran the test. Passes on my machine (Win32)
> everytime.Maybe on linux it gives an incorrect ordering sometimes. So, unless
> you see the incorrect order everytime you run the test, I guess the patch
> should be good.

I do see it everytime. Regardless of with/without the close() calls, regardless
of the JRE used: I never see this one test pass.

Perhaps I should just release this patch and open a separate bug on the
ordering issue?
OTOH, I see no reason to actually check the ordering so we could simply
make the test order-independent, right?
Comment 6 Ayushman Jain CLA 2011-11-09 09:22:30 EST
(In reply to comment #5)
> OTOH, I see no reason to actually check the ordering so we could simply
> make the test order-independent, right?

Exactly. I meant to write the same in my previous comment :)
Comment 7 Stephan Herrmann CLA 2011-11-09 09:44:53 EST
Created attachment 206697 [details]
patch with sorting

(In reply to comment #6)
> (In reply to comment #5)
> > OTOH, I see no reason to actually check the ordering so we could simply
> > make the test order-independent, right?
> 
> Exactly. I meant to write the same in my previous comment :)

Here's a variant with sorting the result before comparison.
I've tried it with a number of different JREs.
To be released unless anybody shouts :)
Comment 8 Stephan Herrmann CLA 2011-11-09 09:53:09 EST
Released for 3.8 M4 
via commit 2a6ccc4326c5f51715033b769f3fad2752538c59
Comment 9 Satyam Kandula CLA 2011-12-05 11:31:47 EST
The change in AbstractCompilerToolTest.java doesn't look completely correct. It is ok to close the manager if it is coming from the standard manager, however it should not be closed if it is being passed as the argument.
Comment 10 Stephan Herrmann CLA 2011-12-05 14:58:08 EST
(In reply to comment #9)
> The change in AbstractCompilerToolTest.java doesn't look completely correct. It
> is ok to close the manager if it is coming from the standard manager, however
> it should not be closed if it is being passed as the argument.

Are you saying this, because you think it could break the tests?
-> currently doesn't. Do you see danger that future tests will
   break because of this?

Or is it more the conceptual question, why the warning was issued in the
first place (since the current method doesn't have the sole responsibility)?
Comment 11 Satyam Kandula CLA 2011-12-05 23:36:26 EST
(In reply to comment #10) 
> Are you saying this, because you think it could break the tests?
> -> currently doesn't. Do you see danger that future tests will
>    break because of this?
Yes, the current tests don't fail because of this, but it could break future tests and I don't think this is a good idea to close the file that is passed as an argument. 
 
> Or is it more the conceptual question, why the warning was issued in the
> first place (since the current method doesn't have the sole responsibility)?
Yes, it is also conceptual. I think you wan to address this through bug 361407.
Comment 12 Satyam Kandula CLA 2011-12-06 06:46:47 EST
Filed bug 365710 to take care of the changes.
Comment 13 Satyam Kandula CLA 2011-12-06 06:48:59 EST
Verified for 3.8M4 using build I20111202-0800