Apache Solr open-source search software
LUCENE-5473: throw IAE not NPE when synonym map was empty
Michael McCandless0082b500ce40
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 90c41998581..1e4d3b8cfda 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -84,6 +84,10 @@ Bug fixesempty list of clauses. This can happen for example, when a wildcard matchesno terms. (Tim Allison via Robert Muir)+* LUCENE-5473: Throw IllegalArgumentException, not+ NullPointerException, if the synonym map is empty when creating+ SynonymFilter (帅广应 via Mike McCandless)+Test Framework* LUCENE-5449: Rename _TestUtil and _TestHelper to remove the leading _.diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilter.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilter.javaindex bd871ea6646..a83366739c0 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilter.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/SynonymFilter.java@@ -263,10 +263,10 @@ public final class SynonymFilter extends TokenFilter {this.synonyms = synonyms;this.ignoreCase = ignoreCase;this.fst = synonyms.fst;- this.fstReader = fst.getBytesReader();if (fst == null) {throw new IllegalArgumentException("fst must be non-null");}+ this.fstReader = fst.getBytesReader();// Must be 1+ so that when roll buffer is at full// lookahead we can distinguish this full buffer fromdiff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSynonymMapFilter.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSynonymMapFilter.javaindex 946c902af6b..ceabc4a32c2 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSynonymMapFilter.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSynonymMapFilter.java@@ -926,4 +926,16 @@ public class TestSynonymMapFilter extends BaseTokenStreamTestCase {new int[] { 8, 22, 15, 22 },new int[] { 1, 0, 1, 1 });}++ public void testEmpty() throws Exception {+ Tokenizer tokenizer = new MockTokenizer();+ tokenizer.setReader(new StringReader("aa bb"));+ try {+ new SynonymFilter(tokenizer, new SynonymMap.Builder(true).build(), true);+ fail("did not hit expected exception");+ } catch (IllegalArgumentException iae) {+ // expected+ assertEquals("fst must be non-null", iae.getMessage());+ }+ }}