You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/04/25 20:06:58 UTC
[solr] branch branch_9x updated: SOLR-16168: Spellcheck NPE if invalid dictionary name is provided (#821)
This is an automated email from the ASF dual-hosted git repository.
krisden 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 ce464834d9a SOLR-16168: Spellcheck NPE if invalid dictionary name is provided (#821)
ce464834d9a is described below
commit ce464834d9a2da25bb195c824f1aa6d5d22c4776
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Mon Apr 25 16:03:53 2022 -0400
SOLR-16168: Spellcheck NPE if invalid dictionary name is provided (#821)
---
solr/CHANGES.txt | 2 ++
.../handler/component/SpellCheckComponent.java | 41 +++++++++++-----------
.../handler/component/SpellCheckComponentTest.java | 38 ++++++++++++++++++++
3 files changed, 60 insertions(+), 21 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9d13ff71aa6..a985936a83d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -43,6 +43,8 @@ Bug Fixes
* SOLR-13044: Fix NPE during core close racing with index replication check. (David Smiley, hossman)
+* SOLR-16168: Spellcheck NPE if invalid dictionary name is provided (Kevin Risden)
+
Other Changes
---------------------
* SOLR-15897: Remove <jmx/> from all unit test solrconfig.xml files. (Eric Pugh)
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
index 0406243cbef..4457d773f87 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
@@ -131,23 +131,23 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
return;
}
boolean shardRequest = "true".equals(params.get(ShardParams.IS_SHARD));
- String q = params.get(SPELLCHECK_Q);
- SolrSpellChecker spellChecker = getSpellChecker(params);
- Collection<Token> tokens = null;
- if (q != null) {
- // we have a spell check param, tokenize it with the query analyzer applicable for this
- // spellchecker
- tokens = getTokens(q, spellChecker.getQueryAnalyzer());
- } else {
- q = rb.getQueryString();
- if (q == null) {
- q = params.get(CommonParams.Q);
+ SolrSpellChecker spellChecker = getSpellChecker(params);
+ if (spellChecker != null) {
+ Collection<Token> tokens;
+ String q = params.get(SPELLCHECK_Q);
+ if (q != null) {
+ // we have a spell check param, tokenize it with the query analyzer applicable for this
+ // spellchecker
+ tokens = getTokens(q, spellChecker.getQueryAnalyzer());
+ } else {
+ q = rb.getQueryString();
+ if (q == null) {
+ q = params.get(CommonParams.Q);
+ }
+ tokens = queryConverter.convert(q);
}
- tokens = queryConverter.convert(q);
- }
- if (tokens != null && tokens.isEmpty() == false) {
- if (spellChecker != null) {
+ if (tokens != null && tokens.isEmpty() == false) {
int count = params.getInt(SPELLCHECK_COUNT, 1);
boolean onlyMorePopular =
params.getBool(SPELLCHECK_ONLY_MORE_POPULAR, DEFAULT_ONLY_MORE_POPULAR);
@@ -215,13 +215,12 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
}
rb.rsp.add("spellcheck", response);
-
- } else {
- throw new SolrException(
- SolrException.ErrorCode.NOT_FOUND,
- "Specified dictionaries do not exist: "
- + getDictionaryNameAsSingleString(getDictionaryNames(params)));
}
+ } else {
+ throw new SolrException(
+ SolrException.ErrorCode.NOT_FOUND,
+ "Specified dictionaries do not exist: "
+ + getDictionaryNameAsSingleString(getDictionaryNames(params)));
}
}
diff --git a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
index 24de8bbb109..543fe94de7a 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
@@ -21,6 +21,7 @@ import java.util.*;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SpellingParams;
@@ -289,6 +290,43 @@ public class SpellCheckComponentTest extends SolrTestCaseJ4 {
"/spellcheck/suggestions/foo=={'numFound':1, 'startOffset':2, 'endOffset':3, 'suggestion':['bar']}");
}
+ @Test
+ public void testInvalidDictionary() throws Exception {
+ assertQEx(
+ "Invalid specified dictionary should throw exception",
+ "Specified dictionaries do not exist: INVALID",
+ req(
+ "json.nl",
+ "map",
+ "qt",
+ rh,
+ SpellCheckComponent.COMPONENT_NAME,
+ "true",
+ "q",
+ "documemt",
+ SpellingParams.SPELLCHECK_DICT,
+ "INVALID"),
+ SolrException.ErrorCode.NOT_FOUND);
+
+ assertQEx(
+ "Invalid specified dictionary should throw exception",
+ "Specified dictionaries do not exist: INVALID2",
+ req(
+ "json.nl",
+ "map",
+ "qt",
+ rh,
+ SpellCheckComponent.COMPONENT_NAME,
+ "true",
+ "q",
+ "test",
+ SpellingParams.SPELLCHECK_Q,
+ "documemt",
+ SpellingParams.SPELLCHECK_DICT,
+ "INVALID2"),
+ SolrException.ErrorCode.NOT_FOUND);
+ }
+
@Test
public void testCollate() throws Exception {
assertJQ(