From ffc746e3d008338c7ae2bf0af83429f444c8061f Mon Sep 17 00:00:00 2001 From: Daniel Naber Date: Sun, 14 Nov 2004 13:26:28 +0000 Subject: [PATCH] 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 --- src/java/org/apache/lucene/search/IndexSearcher.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/java/org/apache/lucene/search/IndexSearcher.java b/src/java/org/apache/lucene/search/IndexSearcher.java index 630eef261b5..80822568058 100644 --- a/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/src/java/org/apache/lucene/search/IndexSearcher.java @@ -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]);