Apache Lucene open-source search software
SOLR-3683: Improved error handling if an <analyzer> contains both an explicit class attribute, as well as nested factories. (hossman)
Chris M. Hostettere9742e61650f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a023aaedc11..37f12b2cffe 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -185,6 +185,8 @@ Other Changes* SOLR-3215: Clone SolrInputDocument when distrib indexing so that update processors afterthe distrib update process do not process the document twice. (Mark Miller)+* SOLR-3683: Improved error handling if an <analyzer> contains both an+ explicit class attribute, as well as nested factories. (hossman)================== 4.0.0-ALPHA ==================More information about this release, including any errata related to thediff --git a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.javaindex 23d32452260..1e21634c5d8 100644--- a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java+++ b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java@@ -225,7 +225,30 @@ public final class FieldTypePluginLoaderif (node == null) return null;NamedNodeMap attrs = node.getAttributes();String analyzerName = DOMUtil.getAttr(attrs,"class");++ // check for all of these up front, so we can error if used in+ // conjunction with an explicit analyzer class.+ NodeList charFilterNodes = (NodeList)xpath.evaluate+ ("./charFilter", node, XPathConstants.NODESET);+ NodeList tokenizerNodes = (NodeList)xpath.evaluate+ ("./tokenizer", node, XPathConstants.NODESET);+ NodeList tokenFilterNodes = (NodeList)xpath.evaluate+ ("./filter", node, XPathConstants.NODESET);+if (analyzerName != null) {++ // explicitly check for child analysis factories instead of+ // just any child nodes, because the user might have their+ // own custom nodes (ie: <description> or something like that)+ if (0 != charFilterNodes.getLength() ||+ 0 != tokenizerNodes.getLength() ||+ 0 != tokenFilterNodes.getLength()) {+ throw new SolrException+ ( SolrException.ErrorCode.SERVER_ERROR,+ "Configuration Error: Analyzer class='" + analyzerName ++ "' can not be combined with nested analysis factories");+ }+try {// No need to be core-aware as Analyzers are not in the core-aware listfinal Class<? extends Analyzer> clazz = loader.findClass(analyzerName, Analyzer.class);@@ -286,8 +309,7 @@ public final class FieldTypePluginLoader}};- charFilterLoader.load( loader, (NodeList)xpath.evaluate("./charFilter", node, XPathConstants.NODESET) );-+ charFilterLoader.load( loader, charFilterNodes );// Load the Tokenizer// Although an analyzer only allows a single Tokenizer, we load a list to make sure@@ -319,13 +341,12 @@ public final class FieldTypePluginLoader}};- tokenizerLoader.load( loader, (NodeList)xpath.evaluate("./tokenizer", node, XPathConstants.NODESET) );+ tokenizerLoader.load( loader, tokenizerNodes );// Make sure something was loadedif( tokenizers.isEmpty() ) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"analyzer without class or tokenizer & filter list");+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"analyzer without class or tokenizer");}-// Load the Filters@@ -353,7 +374,7 @@ public final class FieldTypePluginLoaderreturn null; // used for map registration}};- filterLoader.load( loader, (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET) );+ filterLoader.load( loader, tokenFilterNodes );return new TokenizerChain(charFilters.toArray(new CharFilterFactory[charFilters.size()]),tokenizers.get(0), filters.toArray(new TokenFilterFactory[filters.size()]));diff --git a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.javaindex 46d44bc9b7c..79e9de8a8c7 100644--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java@@ -49,6 +49,7 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {public void testSevereErrorsForUnexpectedAnalyzer() throws Exception {doTest("bad-schema-nontext-analyzer.xml", "StrField (bad_type)");+ doTest("bad-schema-analyzer-class-and-nested.xml", "bad_type");}public void testBadExternalFileField() throws Exception {