fix potiential NPE

This commit is contained in:
Simon Willnauer 2014-10-30 17:48:46 +01:00
parent c4428b12e1
commit 41f6aab388
2 changed files with 11 additions and 4 deletions

View file

@ -81,8 +81,11 @@ public class DocIdSets {
return set;
}
// TODO: should we use WAH8DocIdSet like Lucene?
FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc());
it = set.iterator();
if (it == null) {
return DocIdSet.EMPTY;
}
FixedBitSet fixedBitSet = new FixedBitSet(reader.maxDoc());
long cost = it.cost();
fixedBitSet.or(it);
return new BitDocIdSet(fixedBitSet, cost);

View file

@ -70,6 +70,7 @@ import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.*;
/**
@ -2005,7 +2006,6 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
assertNoFailures(scrollResponse);
assertThat(scrollResponse.getHits().totalHits(), equalTo(10l));
int scannedDocs = 0;
do {
scrollResponse = client()
@ -2232,7 +2232,7 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
}
SearchResponse MinMaxQuery(String scoreType, int minChildren, int maxChildren, int cutoff) throws SearchPhaseExecutionException {
return client()
SearchResponse response = client()
.prepareSearch("test")
.setQuery(
QueryBuilders
@ -2244,15 +2244,19 @@ public class SimpleChildQuerySearchTests extends ElasticsearchIntegrationTest {
.add(FilterBuilders.termFilter("foo", "four"), factorFunction(1))).scoreType(scoreType)
.minChildren(minChildren).maxChildren(maxChildren).setShortCircuitCutoff(cutoff))
.addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
assertSearchResponse(response);
return response;
}
SearchResponse MinMaxFilter( int minChildren, int maxChildren, int cutoff) throws SearchPhaseExecutionException {
return client()
SearchResponse response = client()
.prepareSearch("test")
.setQuery(
QueryBuilders.constantScoreQuery(FilterBuilders.hasChildFilter("child", termFilter("foo", "two"))
.minChildren(minChildren).maxChildren(maxChildren).setShortCircuitCutoff(cutoff)))
.addSort("id", SortOrder.ASC).setTrackScores(true).get();
assertSearchResponse(response);
return response;
}