Return NO_INTERVALS rather than null from empty TokenStream (#42750)
IntervalBuilder#analyzeText will currently return null if it is passed an empty TokenStream, which can lead to a confusing NullPointerException later on during querying. This commit changes the code to return NO_INTERVALS instead. Fixes #42587
This commit is contained in:
parent
61c6a26b31
commit
d0da30e5f4
|
@ -96,7 +96,7 @@ public class IntervalBuilder {
|
|||
// formulate a single term, boolean, or phrase.
|
||||
|
||||
if (numTokens == 0) {
|
||||
return null;
|
||||
return NO_INTERVALS;
|
||||
} else if (numTokens == 1) {
|
||||
// single term
|
||||
return analyzeTerm(stream);
|
||||
|
@ -231,7 +231,7 @@ public class IntervalBuilder {
|
|||
return clauses;
|
||||
}
|
||||
|
||||
private static final IntervalsSource NO_INTERVALS = new IntervalsSource() {
|
||||
static final IntervalsSource NO_INTERVALS = new IntervalsSource() {
|
||||
|
||||
@Override
|
||||
public IntervalIterator intervals(String field, LeafReaderContext ctx) {
|
||||
|
|
|
@ -110,6 +110,12 @@ public class IntervalBuilderTests extends ESTestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testEmptyTokenStream() throws IOException {
|
||||
CannedTokenStream ts = new CannedTokenStream();
|
||||
IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), 0, true);
|
||||
assertSame(IntervalBuilder.NO_INTERVALS, source);
|
||||
}
|
||||
|
||||
public void testSimpleSynonyms() throws IOException {
|
||||
|
||||
CannedTokenStream ts = new CannedTokenStream(
|
||||
|
|
Loading…
Reference in New Issue