| Summary: | Warning building snippetsupport.jar file | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Michael Rennie <Michael_Rennie> |
| Component: | Debug | Assignee: | Michael Rennie <Michael_Rennie> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | markus.kell.r, stephan.herrmann |
| Version: | 3.8 | ||
| Target Milestone: | 3.8 M7 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
Chatting with Markus a bit about this, he figured it is likely a problem with the compiler and not something debug should be doing differently. Passing over to JDT core for inspection. I still see the warning in: Version: 4.2.0 Build id: I20120321-0610 The problem occurs when org.eclipse.jdt.debug.ui is rebuilt and the workbench is running on Java 7.
The project has an Ant builder that invokes the Eclipse compiler using
<javac target="1.5" source="1.5" ...>. The builder runs in the workbench VM, so it gets the class files from there.
In 1.7, URLClassLoader now implements Closeable.
This particular problem could be solved by annotating the variable 'cl' with @SuppressWarnings("resource"). I can't explain why this doesn't issue an 'Unnecessary @SuppressWarnings("resource")' error.
Should we add URLClassLoader to the whitelist?
(In reply to comment #2) > ... I can't explain why this doesn't issue an > 'Unnecessary @SuppressWarnings("resource")' error. Why (or: when) should it? > Should we add URLClassLoader to the whitelist? If everybody agrees I can do that, n.p. I agree the URLClassLoader is not the typical resource for which the warning has been designed, since classloaders typically live much longer than during one method body. > > ... I can't explain why this doesn't issue an > > 'Unnecessary @SuppressWarnings("resource")' error. > > Why (or: when) should it? When I add @SuppressWarnings("resource") on the first line in org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain#evalLoop(URL[]), then I don't get an error, although the project is compiled against a 1.5 JRE, where URLClassLoader doesn't implement Closeable. When I copy the whole "/org.eclipse.jdt.debug.ui/Snippet Support" into a new 1.5 project, I do see the "Unnecessary..." problem. After a lot of digging, I found the reason: org.eclipse.jdt.debug.ui has both resource leak options set to Ignore. That seems to also suppress the 'Unnecessary @SuppressWarnings("resource")' error, which is wrong. Filed bug 376090. > > Should we add URLClassLoader to the whitelist? On second thought, I think we shouldn't add it to the whitelist. If the loader is really only used locally, then it makes sense to close it as early as possible. If it is long lived, then it will be stored in a field or returned from a method, and then no problem will show up. For the concrete issue in ScrapbookMain, I think the right solution is to add this as a child of the <javac> element in /org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml:
<compilerarg value="-warn:-resource"/>
This accounts for the fact that the Ant build can run against a 1.7 JRE, and there, the problem is valid.
Once org.eclipse.jdt.debug.ui moves to 1.7, we'll likely call close() on the classloader.
Moving back to debug.
(In reply to comment #5) > For the concrete issue in ScrapbookMain, I think the right solution is to add > this as a child of the <javac> element in > /org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml: > > <compilerarg value="-warn:-resource"/> Works like a charm, pushed fix to: http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=828be63f38b294a00f69dde878f62402c6b13142 New build output: [mkdir] Created dir: C:\Users\mrennie\git\eclipse.jdt.debug\org.eclipse.jdt.debug.ui\temp.folder\snippetsupport.jar.bin [javac] Compiling 2 source files to C:\Users\mrennie\git\eclipse.jdt.debug\org.eclipse.jdt.debug.ui\temp.folder\snippetsupport.jar.bin [jar] Building jar: C:\Users\mrennie\git\eclipse.jdt.debug\org.eclipse.jdt.debug.ui\snippetsupport.jar [delete] Deleting directory C:\Users\mrennie\git\eclipse.jdt.debug\org.eclipse.jdt.debug.ui\temp.folder build: BUILD SUCCESSFUL Total time: 499 milliseconds Thanks Markus. |
Version: 4.2.0 Build id: I20120308-2200 Was cleaning my whole workspace and saw the following blink by in the console: [mkdir] Created dir: /home/mrennie/git/eclipse.jdt.debug/org.eclipse.jdt.debug.ui/temp.folder/snippetsupport.jar.bin [javac] Compiling 2 source files to /home/mrennie/git/eclipse.jdt.debug/org.eclipse.jdt.debug.ui/temp.folder/snippetsupport.jar.bin [javac] ---------- [javac] 1. WARNING in /home/mrennie/git/eclipse.jdt.debug/org.eclipse.jdt.debug.ui/Snippet Support/org/eclipse/jdt/internal/debug/ui/snippeteditor/ScrapbookMain.java (at line 51) [javac] ClassLoader cl= new URLClassLoader(urls, null); [javac] ^^ [javac] Resource leak: 'cl' is never closed [javac] ---------- [javac] 1 problem (1 warning)