diff --git a/server/src/main/java/org/elasticsearch/common/bytes/BytesReference.java b/server/src/main/java/org/elasticsearch/common/bytes/BytesReference.java index 0a407cb3ad53..21292a92d1dc 100644 --- a/server/src/main/java/org/elasticsearch/common/bytes/BytesReference.java +++ b/server/src/main/java/org/elasticsearch/common/bytes/BytesReference.java @@ -185,9 +185,7 @@ static BytesReference fromByteArray(ByteArray byteArray, int length) { /** * Returns a BytesRefIterator for this BytesReference. This method allows * access to the internal pages of this reference without copying them. - * It must return direct references to the pages, not copies. If the object - * does not hold internal pages, then it mush return Use with care! - * + * It must return direct references to the pages, not copies. Use with care! * * @see BytesRefIterator */ diff --git a/server/src/test/java/org/elasticsearch/common/bytes/ZeroBytesReference.java b/server/src/test/java/org/elasticsearch/common/bytes/ZeroBytesReference.java index 0e405d21a492..ecacc29f4516 100644 --- a/server/src/test/java/org/elasticsearch/common/bytes/ZeroBytesReference.java +++ b/server/src/test/java/org/elasticsearch/common/bytes/ZeroBytesReference.java @@ -61,20 +61,16 @@ public BytesRefIterator iterator() { final byte[] buffer = new byte[Math.min(length, PageCacheRecycler.BYTE_PAGE_SIZE)]; return new BytesRefIterator() { int remaining = length; - BytesRef current; @Override public BytesRef next() { - if (current != null) { - if (IntStream.range(0, current.bytes.length).map(i -> current.bytes[i]).anyMatch(b -> b != 0)) { - throw new AssertionError("Internal pages from ZeroBytesReference must be zero"); - } + if (IntStream.range(0, buffer.length).map(i -> buffer[i]).anyMatch(b -> b != 0)) { + throw new AssertionError("Internal pages from ZeroBytesReference must be zero"); } if (remaining > 0) { final int nextLength = Math.min(remaining, buffer.length); remaining -= nextLength; - current = new BytesRef(buffer, 0, nextLength); - return current; + return new BytesRef(buffer, 0, nextLength); } else { return null; }