[core] Fix classloader closed issue when executing Ant task

Note: the problem (ClassNotFoundExceptions) only shows up with java8
- with java9 the classloader seems to be still usable, even after
we closed it...
This commit is contained in:
Andreas Dangel
2017-12-15 10:32:06 +01:00
parent 99d1e96b1b
commit 02fadc1689

View File

@ -42,6 +42,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.renderers.AbstractRenderer; import net.sourceforge.pmd.renderers.AbstractRenderer;
import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.util.ClasspathClassLoader;
import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.IOUtil;
import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.ResourceLoader;
import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.datasource.DataSource;
@ -275,7 +276,11 @@ public class PMDTaskImpl {
doTask(); doTask();
} finally { } finally {
logManager.close(); logManager.close();
IOUtil.tryCloseClassLoader(configuration.getClassLoader()); // only close the classloader, if it is ours. Otherwise we end up with class not found
// exceptions
if (configuration.getClassLoader() instanceof ClasspathClassLoader) {
IOUtil.tryCloseClassLoader(configuration.getClassLoader());
}
} }
} }