diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index 61642662338..623331ce38a 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -580,6 +580,7 @@ public class CoreContainer zkSys.close(); } + org.apache.lucene.util.IOUtils.closeWhileHandlingException(loader); // best effort } public void cancelCoreRecoveries() { diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java index 6c19185b4e7..a6d9b2bbed1 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -17,6 +17,7 @@ package org.apache.solr.core; +import java.io.Closeable; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -37,6 +38,7 @@ import org.apache.lucene.analysis.util.TokenizerFactory; import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.DocValuesFormat; +import org.apache.lucene.util.IOUtils; import org.apache.lucene.analysis.util.WordlistLoader; import org.apache.solr.common.ResourceLoader; import org.apache.solr.handler.admin.CoreAdminHandler; @@ -68,7 +70,7 @@ import org.apache.solr.search.QParserPlugin; /** * @since solr 1.3 */ -public class SolrResourceLoader implements ResourceLoader +public class SolrResourceLoader implements ResourceLoader,Closeable { public static final Logger log = LoggerFactory.getLogger(SolrResourceLoader.class); @@ -206,7 +208,9 @@ public class SolrResourceLoader implements ResourceLoader SolrException.log(log, "Can't add element to classloader: " + files[j], e); } } - return URLClassLoader.newInstance(elements, oldLoader.getParent()); + ClassLoader oldParent = oldLoader.getParent(); + IOUtils.closeWhileHandlingException(oldLoader); // best effort + return URLClassLoader.newInstance(elements, oldParent); } // are we still here? return oldLoader; @@ -755,4 +759,9 @@ public class SolrResourceLoader implements ResourceLoader } throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, builder.toString() ); } + + @Override + public void close() throws IOException { + IOUtils.close(classLoader); + } } diff --git a/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java b/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java index 777aafb0ce2..d5966b6bda1 100644 --- a/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java +++ b/solr/core/src/test/org/apache/solr/core/ResourceLoaderTest.java @@ -181,5 +181,6 @@ public class ResourceLoaderTest extends LuceneTestCase // null file filter means accept all (making otherFile accessible) loader.addToClassLoader("otherLib", null, false); assertNotNull(loader.getClassLoader().getResource("otherFile")); + loader.close(); } }