mirror of https://github.com/apache/lucene.git
LUCENE-8568: TestMockDirectoryWrapper/ RAMInputStream NPE.
This commit is contained in:
parent
25bca6f165
commit
bd3ce916bd
|
@ -72,17 +72,24 @@ public class RAMInputStream extends IndexInput implements Cloneable {
|
||||||
if (bufferPosition == bufferLength) {
|
if (bufferPosition == bufferLength) {
|
||||||
nextBuffer();
|
nextBuffer();
|
||||||
}
|
}
|
||||||
return currentBuffer[bufferPosition++];
|
if (currentBuffer == null) {
|
||||||
|
throw new EOFException();
|
||||||
|
} else {
|
||||||
|
return currentBuffer[bufferPosition++];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readBytes(byte[] b, int offset, int len) throws IOException {
|
public void readBytes(byte[] b, int offset, int len) throws IOException {
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
|
|
||||||
if (bufferPosition == bufferLength) {
|
if (bufferPosition == bufferLength) {
|
||||||
nextBuffer();
|
nextBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentBuffer == null) {
|
||||||
|
throw new EOFException();
|
||||||
|
}
|
||||||
|
|
||||||
int remainInBuffer = bufferLength - bufferPosition;
|
int remainInBuffer = bufferLength - bufferPosition;
|
||||||
int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;
|
int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;
|
||||||
System.arraycopy(currentBuffer, bufferPosition, b, offset, bytesToCopy);
|
System.arraycopy(currentBuffer, bufferPosition, b, offset, bytesToCopy);
|
||||||
|
|
|
@ -522,6 +522,9 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
|
||||||
|
|
||||||
// But any read following the seek(len) should throw an EOFException.
|
// But any read following the seek(len) should throw an EOFException.
|
||||||
expectThrows(EOFException.class, i::readByte);
|
expectThrows(EOFException.class, i::readByte);
|
||||||
|
expectThrows(EOFException.class, () -> {
|
||||||
|
i.readBytes(new byte [1], 0, 1);
|
||||||
|
});
|
||||||
|
|
||||||
i.close();
|
i.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue