throw IllegalArgumentException for nDocs <= 0 to avoid NullPointerException

PR: 32227
Submitted by: Paul Elschot


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2004-11-14 13:26:28 +00:00
parent bcfcf9eeb7
commit ffc746e3d0
1 changed files with 4 additions and 0 deletions

View File

@ -83,6 +83,10 @@ public class IndexSearcher extends Searcher {
// inherit javadoc
public TopDocs search(Query query, Filter filter, final int nDocs)
throws IOException {
if (nDocs <= 0) // null might be returned from hq.top() below.
throw new IllegalArgumentException("nDocs must be > 0");
Scorer scorer = query.weight(this).scorer(reader);
if (scorer == null)
return new TopDocs(0, new ScoreDoc[0]);