Bug 434464 - Resource leak in APT classloader
Summary: Resource leak in APT classloader
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.5 M1   Edit
Assignee: Harry Terkelsen CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-08 21:50 EDT by Harry Terkelsen CLA
Modified: 2015-01-22 21:25 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harry Terkelsen CLA 2014-05-08 21:50:46 EDT
APT uses URLClassLoader, which opens streams on its resources and does not ensure they are closed until URLClassLoader.close() is called. When APT clears its cached classloaders (org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.uncacheProject(IJavaProject), org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.resetAll(), org.eclipse.jdt.apt.core.internal.AnnotationProcessorFactoryLoader.resetBatchProcessors(IJavaProject)), it only calls close() on the classloader if it is a JarClassLoader (a class which is actually not used anywhere). This means that resources opened by URLClassLoader are never closed.

I propose that the code is changed to check if the classloader is a URLClassLoader instead of JarClassLoader.
Comment 1 Jay Arthanareeswaran CLA 2014-05-09 01:22:42 EDT
(In reply to Harry Terkelsen from comment #0)
> it only calls close() on the
> classloader if it is a JarClassLoader (a class which is actually not used
> anywhere).

I am surprised, but you are right. The only place where we seem to refer to JarClassLoader is in those instanceof checks.

> I propose that the code is changed to check if the classloader is a
> URLClassLoader instead of JarClassLoader.

I will look into this.
Comment 2 Jay Arthanareeswaran CLA 2014-05-09 01:31:19 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #1)
> I will look into this.

Hmm... URLClassLoader#close() is a 1.7 method and the apt.core project is still at 1.5. More importantly, eclipse needs to run with a 1.6 JRE :(
Comment 3 Sergey Prigogin CLA 2014-05-09 12:13:59 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #2)
> Hmm... URLClassLoader#close() is a 1.7 method and the apt.core project is
> still at 1.5. More importantly, eclipse needs to run with a 1.6 JRE :(

You can do something like:
  if (classLoader instanceof Closeable)
    ((Closeable) classLoader).close();

This would not eliminate the resource leak under JRE 1.6, but under JRE 1.7 the problem would be fixed.
Comment 4 Sergey Prigogin CLA 2014-07-25 19:26:08 EDT
A proposed fix is in https://git.eclipse.org/r/#/c/30473/.
Comment 5 Jay Arthanareeswaran CLA 2014-07-30 12:31:25 EDT
Thanks Harry. Released in master for M1.
Comment 6 shankha banerjee CLA 2014-08-05 22:52:40 EDT
The code is verified by inspection.
The class JarClassLoader (functions and constructors) is not referred at all.

Verified for 4.5 M1 using I20140804-2000 build.

Thanks