SOLR-5661: catch too-large priority queue

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1561369 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-01-25 19:09:28 +00:00
parent 9ed426cbd4
commit 3ae719d025
2 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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;
}
}
/**