Author: bodewig Date: Tue Sep 1 14:10:12 2009 New Revision: 810063 URL: http://svn.apache.org/viewvc?rev=810063&view=rev Log: ensure classloaders get cleaned up when no longer needed
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java?rev=810063&r1=810062&r2=810063&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java Tue Sep 1 14:10:12 2009 @@ -24,6 +24,7 @@ import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.util.FileUtils; +import java.io.FilterInputStream; import java.io.InputStream; import java.io.IOException; import java.util.Stack; @@ -172,6 +173,7 @@ } dieOnCircularReference(); ClassLoader cl = null; + boolean clNeedsCleanup = false; if (loader != null) { cl = (ClassLoader) loader.getReferencedObject(); } @@ -186,6 +188,7 @@ getProject(), p, false); } + clNeedsCleanup = loader != null; } else { cl = JavaResource.class.getClassLoader(); } @@ -194,7 +197,22 @@ } } - return openInputStream(cl); + final ClassLoader classLoader = cl; + return !clNeedsCleanup + ? openInputStream(cl) + : new FilterInputStream(openInputStream(cl)) { + public void close() throws IOException { + FileUtils.close(in); + ((AntClassLoader) classLoader).cleanup(); + } + protected void finalize() throws Throwable { + try { + close(); + } finally { + super.finalize(); + } + } + }; } /**