Apache Solr open-source search software
LUCENE-8568: TestMockDirectoryWrapper/ RAMInputStream NPE.
Dawid Weissbd3ce916bd19
diff --git a/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java b/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.javaindex cb07b6e42ca..312d6383cd8 100644--- a/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java+++ b/lucene/core/src/java/org/apache/lucene/store/RAMInputStream.java@@ -72,17 +72,24 @@ public class RAMInputStream extends IndexInput implements Cloneable {if (bufferPosition == bufferLength) {nextBuffer();}- return currentBuffer[bufferPosition++];+ if (currentBuffer == null) {+ throw new EOFException();+ } else {+ return currentBuffer[bufferPosition++];+ }}@Overridepublic void readBytes(byte[] b, int offset, int len) throws IOException {while (len > 0) {-if (bufferPosition == bufferLength) {nextBuffer();}+ if (currentBuffer == null) {+ throw new EOFException();+ }+int remainInBuffer = bufferLength - bufferPosition;int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;System.arraycopy(currentBuffer, bufferPosition, b, offset, bytesToCopy);diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.javaindex e49000b5597..d9eeb88aea1 100644--- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java@@ -522,6 +522,9 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {// But any read following the seek(len) should throw an EOFException.expectThrows(EOFException.class, i::readByte);+ expectThrows(EOFException.class, () -> {+ i.readBytes(new byte [1], 0, 1);+ });i.close();}