You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2020/09/29 06:19:52 UTC
[lucene-solr] 01/04: SOLR-14151: inform() was invoked with the
wrong resource loader
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 5ad8c891a19b9336825a1f1bd572d5fe08937192
Author: noblepaul <no...@gmail.com>
AuthorDate: Thu Sep 17 13:11:33 2020 +1000
SOLR-14151: inform() was invoked with the wrong resource loader
---
.../java/org/apache/solr/schema/IndexSchema.java | 37 ++++++++++++++++++++--
.../org/apache/solr/schema/ManagedIndexSchema.java | 6 ++--
2 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index bd4ae7e..26286c2 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -20,6 +20,7 @@ import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import java.io.IOException;
+import java.io.InputStream;
import java.io.Writer;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
@@ -46,6 +47,7 @@ import java.util.stream.Stream;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
+import org.apache.lucene.analysis.util.ResourceLoader;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.payloads.PayloadDecoder;
import org.apache.lucene.search.similarities.Similarity;
@@ -136,6 +138,7 @@ public class IndexSchema {
protected final Version luceneVersion;
protected float version;
protected final SolrResourceLoader loader;
+ protected ResourceLoader resourceLoader;
protected final SolrClassLoader solrClassLoader;
protected final Properties substitutableProperties;
@@ -181,7 +184,7 @@ public class IndexSchema {
this.resourceName = Objects.requireNonNull(name);
try {
readSchema(is);
- loader.inform(loader);
+ loader.inform(this.resourceLoader);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -190,8 +193,36 @@ public class IndexSchema {
protected IndexSchema(Version luceneVersion, SolrResourceLoader loader, Properties substitutableProperties) {
this.luceneVersion = Objects.requireNonNull(luceneVersion);
this.loader = loader;
- this.solrClassLoader = loader.getSchemaLoader() == null ? loader : loader.getSchemaLoader();
- this.substitutableProperties = substitutableProperties;
+ this.solrClassLoader = loader.getSchemaLoader() == null ?
+ loader :
+ loader.getSchemaLoader();
+ resourceLoader = this.solrClassLoader instanceof SolrResourceLoader ?
+ (ResourceLoader) this.solrClassLoader :
+ wrappedResourceLoader(this.solrClassLoader);
+ this.substitutableProperties = substitutableProper`ties;
+ }
+
+ /**We want resources to be loaded using {@link SolrResourceLoader}
+ * and classes to be loaded using {@link org.apache.solr.pkg.PackageListeningClassLoader}
+ *
+ */
+ private ResourceLoader wrappedResourceLoader(SolrClassLoader solrClassLoader) {
+ return new ResourceLoader() {
+ @Override
+ public InputStream openResource(String resource) throws IOException {
+ return loader.openResource(resource);
+ }
+
+ @Override
+ public <T> Class<? extends T> findClass(String cname, Class<T> expectedType) {
+ return solrClassLoader.findClass(cname, expectedType);
+ }
+
+ @Override
+ public <T> T newInstance(String cname, Class<T> expectedType) {
+ return solrClassLoader.newInstance(cname, expectedType);
+ }
+ };
}
/**
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 d44e961..2b4314f 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchema.java
@@ -1319,7 +1319,7 @@ public final class ManagedIndexSchema extends IndexSchema {
for (CharFilterFactory next : charFilters) {
if (next instanceof ResourceLoaderAware) {
try {
- ((ResourceLoaderAware) next).inform(loader);
+ ((ResourceLoaderAware) next).inform(resourceLoader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
@@ -1329,7 +1329,7 @@ public final class ManagedIndexSchema extends IndexSchema {
TokenizerFactory tokenizerFactory = chain.getTokenizerFactory();
if (tokenizerFactory instanceof ResourceLoaderAware) {
try {
- ((ResourceLoaderAware) tokenizerFactory).inform(loader);
+ ((ResourceLoaderAware) tokenizerFactory).inform(resourceLoader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
@@ -1339,7 +1339,7 @@ public final class ManagedIndexSchema extends IndexSchema {
for (TokenFilterFactory next : filters) {
if (next instanceof ResourceLoaderAware) {
try {
- ((ResourceLoaderAware) next).inform(loader);
+ ((ResourceLoaderAware) next).inform(resourceLoader);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}