diff --git a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java index 8e4cc78b960..52bc8351274 100644 --- a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java +++ b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java @@ -29,7 +29,7 @@ package org.apache.lucene.util; * @lucene.internal */ public abstract class PriorityQueue { - private int size; + private int size = 0; private final int maxSize; private final T[] heap; @@ -37,10 +37,8 @@ public abstract class PriorityQueue { this(maxSize, true); } - @SuppressWarnings("unchecked") public PriorityQueue(int maxSize, boolean prepopulate) { - size = 0; - int heapSize; + final int heapSize; if (0 == maxSize) { // We allocate 1 extra to avoid if statement in top() heapSize = 2; @@ -62,7 +60,9 @@ public abstract class PriorityQueue { heapSize = maxSize + 1; } } - heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works always + // T is unbounded type, so this unchecked cast works always: + @SuppressWarnings("unchecked") final T[] h = (T[]) new Object[heapSize]; + this.heap = h; this.maxSize = maxSize; if (prepopulate) {