Apache Lucene open-source search software
LUCENE-4971: fix NPE in AnalyzingSuggester when there are too many graph expansions
Michael McCandlessb3d70e8f6995
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 9c22802ec37..1c9c390deee 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -173,6 +173,9 @@ Bug Fixeswhen the sum of those shapes contain the query shape but none do individually.A flag was added to use the original faster algorithm. (David Smiley)+* LUCENE-4971: Fixed NPE in AnalyzingSuggester when there are too many+ graph expansions. (Alexey Kudinov via Mike McCandless)+Optimizations* LUCENE-4936: Improve numeric doc values compression in case all values sharediff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java b/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.javaindex 0e6adf63556..d479cd78923 100644--- a/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/SpecialOperations.java@@ -219,7 +219,7 @@ final public class SpecialOperations {/*** Returns the set of accepted strings, assuming that at most* <code>limit</code> strings are accepted. If more than <code>limit</code>- * strings are accepted, null is returned. If <code>limit</code><0, then+ * strings are accepted, the first limit strings found are returned. If <code>limit</code><0, then* the limit is infinite.*/public static Set<IntsRef> getFiniteStrings(Automaton a, int limit) {@@ -227,11 +227,9 @@ final public class SpecialOperations {if (a.isSingleton()) {if (limit > 0) {strings.add(Util.toUTF32(a.singleton, new IntsRef()));- } else {- return null;}} else if (!getFiniteStrings(a.initial, new HashSet<State>(), strings, new IntsRef(), limit)) {- return null;+ return strings;}return strings;}diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.javaindex 155446985a5..803c5d91a30 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java@@ -1164,4 +1164,33 @@ public class AnalyzingSuggesterTest extends LuceneTestCase {assertEquals("[isla de muerta/8, i love lucy/7]", suggester.lookup("i", false, 3).toString());assertEquals("[i love lucy/7]", suggester.lookup("i ", false, 3).toString());}++ public void testTooManyExpansions() throws Exception {++ final Analyzer a = new Analyzer() {+ @Override+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {+ Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.SIMPLE, true);++ return new TokenStreamComponents(tokenizer) {+ @Override+ public TokenStream getTokenStream() {+ Token a = new Token("a", 0, 1);+ a.setPositionIncrement(1);+ Token b = new Token("b", 0, 1);+ b.setPositionIncrement(0);+ return new CannedTokenStream(new Token[] {a, b});+ }++ @Override+ protected void setReader(final Reader reader) throws IOException {+ }+ };+ }+ };++ AnalyzingSuggester suggester = new AnalyzingSuggester(a, a, 0, 256, 1);+ suggester.build(new TermFreqArrayIterator(new TermFreq[] {new TermFreq("a", 1)}));+ assertEquals("[a/1]", suggester.lookup("a", false, 1).toString());+ }}