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 69eabc5631c..609da780dbd 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -694,17 +694,24 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL } for (ResourceLoaderAware aware : arr) { - CURRENT_AWARE.set(aware); - try{ - aware.inform(loader); - } finally { - CURRENT_AWARE.remove(); - } + informAware(loader, aware); } } } + /** + * Set the current {@link ResourceLoaderAware} object in thread local so that appropriate classloader can be used for package loaded classes + */ + public static void informAware(ResourceLoader loader, ResourceLoaderAware aware) throws IOException { + CURRENT_AWARE.set(aware); + try{ + aware.inform(loader); + } finally { + CURRENT_AWARE.remove(); + } + } + /** * Register any {@link SolrInfoBean}s * @@ -883,6 +890,6 @@ public class SolrResourceLoader implements ResourceLoader, Closeable, SolrClassL } //This is to verify if this requires to use the schema classloader for classes loaded from packages - public static final ThreadLocal CURRENT_AWARE = new ThreadLocal<>(); + private static final ThreadLocal CURRENT_AWARE = new ThreadLocal<>(); } diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java index c1815e01d45..e7a748c94d1 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java @@ -79,6 +79,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.InputSource; +import static org.apache.solr.core.SolrResourceLoader.informAware; + /** Solr-managed schema - non-user-editable, but can be mutable via internal and external REST API requests. */ public final class ManagedIndexSchema extends IndexSchema { @@ -1324,7 +1326,7 @@ public final class ManagedIndexSchema extends IndexSchema { for (CharFilterFactory next : charFilters) { if (next instanceof ResourceLoaderAware) { try { - ((ResourceLoaderAware) next).inform(loader); + informAware(loader, (ResourceLoaderAware) next); } catch (IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } @@ -1334,7 +1336,7 @@ public final class ManagedIndexSchema extends IndexSchema { TokenizerFactory tokenizerFactory = chain.getTokenizerFactory(); if (tokenizerFactory instanceof ResourceLoaderAware) { try { - ((ResourceLoaderAware) tokenizerFactory).inform(loader); + informAware(loader, (ResourceLoaderAware) tokenizerFactory); } catch (IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); } @@ -1343,13 +1345,10 @@ public final class ManagedIndexSchema extends IndexSchema { TokenFilterFactory[] filters = chain.getTokenFilterFactories(); for (TokenFilterFactory next : filters) { if (next instanceof ResourceLoaderAware) { - SolrResourceLoader.CURRENT_AWARE.set((ResourceLoaderAware) next); try { - ((ResourceLoaderAware) next).inform(loader); + informAware(loader, (ResourceLoaderAware) next); } catch (IOException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); - } finally { - SolrResourceLoader.CURRENT_AWARE.remove(); } } }