lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1561370 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java
Date Sat, 25 Jan 2014 19:11:13 GMT
Author: mikemccand
Date: Sat Jan 25 19:11:13 2014
New Revision: 1561370

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

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1561370&r1=1561369&r2=1561370&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Sat Jan 25 19:11:13 2014
@@ -124,6 +124,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/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java?rev=1561370&r1=1561369&r2=1561370&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java
Sat Jan 25 19:11:13 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;
+    }
   }
   
   /**



Mime
View raw message