lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r887670 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/IndexSearcher.java src/java/org/apache/lucene/util/PriorityQueue.java
Date Sun, 06 Dec 2009 11:41:26 GMT
Author: mikemccand
Date: Sun Dec  6 11:41:26 2009
New Revision: 887670

URL: http://svn.apache.org/viewvc?rev=887670&view=rev
Log:
LUCENE-2119: behave better if you pass Integer.MAX_VALUE as nDcos to search methods

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/java/trunk/src/java/org/apache/lucene/util/PriorityQueue.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=887670&r1=887669&r2=887670&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Sun Dec  6 11:41:26 2009
@@ -32,6 +32,10 @@
   one of the threads before all changes are actually committed.
   (Sanne Grinovero via Mike McCandless)
 
+* LUCENE-2119: Don't throw NegativeArraySizeException if you pass
+  Integer.MAX_VALUE as nDocs to IndexSearcher search methods.  (Paul
+  Taylor via Mike McCandless)
+
 New features
 
 * LUCENE-2069: Added Unicode 4 support to CharArraySet. Due to the switch

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java?rev=887670&r1=887669&r2=887670&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java Sun Dec  6 11:41:26
2009
@@ -158,12 +158,14 @@
 
   // inherit javadoc
   @Override
-  public TopDocs search(Weight weight, Filter filter, final int nDocs) throws IOException
{
+  public TopDocs search(Weight weight, Filter filter, int nDocs) throws IOException {
 
     if (nDocs <= 0) {
       throw new IllegalArgumentException("nDocs must be > 0");
     }
 
+    nDocs = Math.min(nDocs, reader.maxDoc());
+
     TopScoreDocCollector collector = TopScoreDocCollector.create(nDocs, !weight.scoresDocsOutOfOrder());
     search(weight, filter, collector);
     return collector.topDocs();
@@ -186,9 +188,12 @@
    * then pass that to {@link #search(Weight, Filter,
    * Collector)}.</p>
    */
-  public TopFieldDocs search(Weight weight, Filter filter, final int nDocs,
+  public TopFieldDocs search(Weight weight, Filter filter, int nDocs,
                              Sort sort, boolean fillFields)
       throws IOException {
+
+    nDocs = Math.min(nDocs, reader.maxDoc());
+
     TopFieldCollector collector = TopFieldCollector.create(sort, nDocs,
         fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.scoresDocsOutOfOrder());
     search(weight, filter, collector);

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/PriorityQueue.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/PriorityQueue.java?rev=887670&r1=887669&r2=887670&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/PriorityQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/PriorityQueue.java Sun Dec  6 11:41:26
2009
@@ -85,8 +85,18 @@
     if (0 == maxSize)
       // We allocate 1 extra to avoid if statement in top()
       heapSize = 2;
-    else
-      heapSize = maxSize + 1;
+    else {
+      if (maxSize == Integer.MAX_VALUE) {
+        // Don't wrap heapSize to -1, in this case, which
+        // causes a confusing NegativeArraySizeException.
+        // Note that very likely this will simply then hit
+        // an OOME, but at least that's more indicative to
+        // caller that this values is too big:
+        heapSize = Integer.MAX_VALUE;
+      } else {
+        heapSize = maxSize + 1;
+      }
+    }
     heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works
always
     this.maxSize = maxSize;
     



Mime
View raw message