You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2023/05/18 21:53:32 UTC

[solr] branch branch_9x updated: SOLR-16801: Reset the thread's contextClassloader after loading the CoreContainer (#1645)

This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new f7867ec744f SOLR-16801: Reset the thread's contextClassloader after loading the CoreContainer (#1645)
f7867ec744f is described below

commit f7867ec744f102fcc385cecac89ce6d87cee9dc5
Author: Thomas Wöckinger <th...@users.noreply.github.com>
AuthorDate: Thu May 18 23:34:58 2023 +0200

    SOLR-16801: Reset the thread's contextClassloader after loading the CoreContainer (#1645)
    
    Co-authored-by: Thomas Wöckinger <tw...@silbergrau.com>
    Co-authored-by: Houston Putman <ho...@apache.org>
    (cherry picked from commit 0a6a114319cbc2fcda1e36bbcb157e1841555884)
---
 solr/CHANGES.txt                                         |  2 ++
 .../src/java/org/apache/solr/core/CoreContainer.java     | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b9b803e0739..3304d3e2862 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -142,6 +142,8 @@ Bug Fixes
 
 * SOLR-16765: bin/solr export tool limit property was off by 1.  Now limit results exported to the exact number. (Eric Pugh)
 
+* SOLR-16801: Reset the thread's contextClassloader after loading the CoreContainer (Thomas Wöckinger, Houston Putman)
+
 Dependency Upgrades
 ---------------------
 * PR#1494: Upgrade forbiddenapis to 3.5 (Uwe Schindler)
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 6d843b3532b..edde8c34cf3 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java
@@ -746,12 +746,22 @@ public class CoreContainer {
       reason =
           "Set the thread contextClassLoader for all 3rd party dependencies that we cannot control")
   public void load() {
+    final ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
+    try {
+      // Set the thread's contextClassLoader for any plugins that are loaded via Modules or Packages
+      // and have dependencies that use the thread's contextClassLoader
+      Thread.currentThread().setContextClassLoader(loader.getClassLoader());
+      loadInternal();
+    } finally {
+      Thread.currentThread().setContextClassLoader(originalContextClassLoader);
+    }
+  }
+
+  /** Load the cores defined for this CoreContainer */
+  private void loadInternal() {
     if (log.isDebugEnabled()) {
       log.debug("Loading cores into CoreContainer [instanceDir={}]", getSolrHome());
     }
-    // Set the thread's contextClassLoader for any plugins that are loaded via Modules or Packages
-    Thread.currentThread().setContextClassLoader(loader.getClassLoader());
-
     logging = LogWatcher.newRegisteredLogWatcher(cfg.getLogWatcherConfig(), loader);
 
     ClusterEventProducerFactory clusterEventProducerFactory = new ClusterEventProducerFactory(this);