From 02fadc1689a66184c3fb5241859f7519907a4f65 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 15 Dec 2017 10:32:06 +0100 Subject: [PATCH] [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... --- .../java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java index 477232d6ee..734fbf2d51 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java @@ -42,6 +42,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.renderers.AbstractRenderer; import net.sourceforge.pmd.renderers.Renderer; +import net.sourceforge.pmd.util.ClasspathClassLoader; import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.datasource.DataSource; @@ -275,7 +276,11 @@ public class PMDTaskImpl { doTask(); } finally { 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()); + } } }