From 074ccad349257e283607b25308c9b08be9ad44ef Mon Sep 17 00:00:00 2001 From: iverase Date: Fri, 13 Oct 2023 16:54:12 +0200 Subject: [PATCH] doh! friday afternoon --- .../org/elasticsearch/common/bytes/BytesReference.java | 4 +--- .../elasticsearch/common/bytes/ZeroBytesReference.java | 10 +++------- 2 files changed, 4 insertions(+), 10 deletions(-) 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 0a407cb3ad538..21292a92d1dc1 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 0e405d21a492c..ecacc29f45164 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; }