LUCENE-5473: throw IAE not NPE when synonym map was empty

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1571986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-02-26 10:11:54 +00:00
parent c36c4d7264
commit 0082b500ce
3 changed files with 17 additions and 1 deletions

View File

@ -84,6 +84,10 @@ Bug fixes
empty list of clauses. This can happen for example, when a wildcard matches
no 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 _.

View File

@ -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 from

View File

@ -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());
}
}
}