You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/01/25 20:09:29 UTC

svn commit: r1561369 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/util/PriorityQueue.java

Author: mikemccand
Date: Sat Jan 25 19:09:28 2014
New Revision: 1561369

URL: http://svn.apache.org/r1561369
Log:
SOLR-5661: catch too-large priority queue

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1561369&r1=1561368&r2=1561369&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Sat Jan 25 19:09:28 2014
@@ -192,6 +192,9 @@ Bug fixes
   on Lucene 4.6 if any index segments were Lucene 4.0-4.5.
   (Littlestar, Mike McCandless, Shai Erera, Robert Muir)
 
+* SOLR-5661: PriorityQueue now refuses to allocate itself if the
+  incoming maxSize is too large (Raintung Li via Mike McCandless)
+
 API Changes
 
 * LUCENE-5339: The facet module was simplified/reworked to make the

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java?rev=1561369&r1=1561368&r2=1561369&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java Sat Jan 25 19:09:28 2014
@@ -41,11 +41,11 @@ public abstract class PriorityQueue<T> {
   public PriorityQueue(int maxSize, boolean prepopulate) {
     size = 0;
     int heapSize;
-    if (0 == maxSize)
+    if (0 == maxSize) {
       // We allocate 1 extra to avoid if statement in top()
       heapSize = 2;
-    else {
-      if (maxSize == Integer.MAX_VALUE) {
+    } else {
+      if (maxSize > ArrayUtil.MAX_ARRAY_LENGTH) {
         // Don't wrap heapSize to -1, in this case, which
         // causes a confusing NegativeArraySizeException.
         // Note that very likely this will simply then hit
@@ -54,7 +54,8 @@ public abstract class PriorityQueue<T> {
         // in this case, but it's very unlikely in practice
         // one will actually insert this many objects into
         // the PQ:
-        heapSize = Integer.MAX_VALUE;
+    	// Throw exception to prevent confusing OOME:
+        throw new IllegalArgumentException("maxSize must be <= " + ArrayUtil.MAX_ARRAY_LENGTH + "; got: " + maxSize);
       } else {
         // NOTE: we add +1 because all access to heap is
         // 1-based not 0-based.  heap[0] is unused.
@@ -183,8 +184,9 @@ public abstract class PriorityQueue<T> {
       size--;
       downHeap();               // adjust heap
       return result;
-    } else
+    } else {
       return null;
+    }
   }
   
   /**