diff --git a/server/src/main/java/org/elasticsearch/common/util/BitArray.java b/server/src/main/java/org/elasticsearch/common/util/BitArray.java index 24df8f62430..dcd068524cd 100644 --- a/server/src/main/java/org/elasticsearch/common/util/BitArray.java +++ b/server/src/main/java/org/elasticsearch/common/util/BitArray.java @@ -66,6 +66,9 @@ public final class BitArray implements Releasable { public long nextSetBit(long index) { long wordNum = wordNum(index); + if (wordNum >= bits.size()) { + return Long.MAX_VALUE; + } long word = bits.get(wordNum) >> index; // skip all the bits to the right of index if (word!=0) {