osheroff / mysql-binlog-connector-java

MySQL Binary Log connector
641 stars 161 forks source link

ByteArrayInputStream will throw unexcepted EOFException #116

Open LoveHeat opened 11 months ago

LoveHeat commented 11 months ago

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