osheroff/mysql-binlog-connector-java

ByteArrayInputStream will throw unexcepted EOFException

Opened this issue · 0 comments

The way we use ByteArrayInputStream is:
call enterBlock() ---> call mark() ---> call readInteger() ---> call reset()
after reset() is called, we will call read again, but it will throw EOFException, after review code, i found the reason maybe that we don't reset blockLength after reset() is called, the test code can simulate the bug:

@Test
public void testMarkAndReset() throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {1, 2, 3, 4});
    in.enterBlock(4);
    in.mark(4);
    in.readInteger(4);
    in.reset();

    assertEquals(1, in.read());
}