LUCENE-8568: TestMockDirectoryWrapper/ RAMInputStream NPE.

This commit is contained in:
Dawid Weiss 2018-11-20 13:37:29 +01:00
parent 25bca6f165
commit bd3ce916bd
2 changed files with 12 additions and 2 deletions

View File

@ -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++];
}
}
@Override
public 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);

View File

@ -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();
}