From ed28039c43747430372b7da551940316911e199b Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sun, 6 Nov 2011 11:38:42 +0000 Subject: [PATCH] LUCENE-3563: fix test bug git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1198341 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/src/java/org/apache/lucene/util/PagedBytes.java | 2 ++ lucene/src/test/org/apache/lucene/util/TestPagedBytes.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/util/PagedBytes.java b/lucene/src/java/org/apache/lucene/util/PagedBytes.java index 2e29464b90d..983f3bab69c 100644 --- a/lucene/src/java/org/apache/lucene/util/PagedBytes.java +++ b/lucene/src/java/org/apache/lucene/util/PagedBytes.java @@ -441,6 +441,7 @@ public final class PagedBytes { @Override public void readBytes(byte[] b, int offset, int len) { + assert b.length >= offset + len; final int offsetEnd = offset + len; while (true) { final int blockLeft = blockSize - currentBlockUpto; @@ -485,6 +486,7 @@ public final class PagedBytes { @Override public void writeBytes(byte[] b, int offset, int length) throws IOException { + assert b.length >= offset + length; if (length == 0) { return; } diff --git a/lucene/src/test/org/apache/lucene/util/TestPagedBytes.java b/lucene/src/test/org/apache/lucene/util/TestPagedBytes.java index 5205300b027..73e84bd4bf7 100644 --- a/lucene/src/test/org/apache/lucene/util/TestPagedBytes.java +++ b/lucene/src/test/org/apache/lucene/util/TestPagedBytes.java @@ -37,7 +37,7 @@ public class TestPagedBytes extends LuceneTestCase { if (random.nextInt(10) == 7) { out.writeByte(answer[written++]); } else { - int chunk = Math.max(random.nextInt(1000), numBytes - written); + int chunk = Math.min(random.nextInt(1000), numBytes - written); out.writeBytes(answer, written, chunk); written += chunk; } @@ -53,7 +53,7 @@ public class TestPagedBytes extends LuceneTestCase { if (random.nextInt(10) == 7) { verify[read++] = in.readByte(); } else { - int chunk = Math.max(random.nextInt(1000), numBytes - read); + int chunk = Math.min(random.nextInt(1000), numBytes - read); in.readBytes(verify, read, chunk); read += chunk; }