@Test
public void testToStringDoesNotThrowIndexOutOfBounds() {

    CompositeByteBuf buffer = Unpooled.compositeBuffer();
    try {
        byte[] bytes = "1234".getBytes(CharsetUtil.UTF_8);
        buffer.addComponent(Unpooled.buffer(bytes.length).writeBytes(bytes));
        buffer.addComponent(Unpooled.buffer(bytes.length).writeBytes(bytes));
        assertEquals("1234", buffer.toString(bytes.length, bytes.length, CharsetUtil.UTF_8));
    } finally {
        buffer.release();
    }
}