final ByteBuffer bb = ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, 1, 3);
System.err.println("bb.lim = " + bb.limit());
final ByteArrayBufferedData babd = new ByteArrayBufferedData(bb);
System.err.println("babd.len = " + babd.length());
prints
As far as the ByteBuffer is concerned, the behavior is correct per the ByteBuffer javadoc.
However, while the current ByteArrayBufferedData(ByteBuffer) ctor or a similar wrap(, offset, length) method also behave per their current javadoc, the result returned by the length() method is incorrect. We wrapped a ByteBuffer of length 3 (see the last argument at the first line of code), so the length of the BufferedData object must also be 3, which currently it isn't because:
/** {@inheritDoc} */
@Override
public long length() {
return buffer.limit();
}
and this code can only return the correct result if the offset of the buffer is zero, and also, only if the client code never modified the limit via the BufferedData APIs.
We even have unit tests that verify these odd results.
We need to revisit offsets/limits/lengths handling, fix bugs, update the unit tests, and then verify if the CN code still works and doesn't rely on the current incorrect behavior.
prints
As far as the ByteBuffer is concerned, the behavior is correct per the ByteBuffer javadoc.
However, while the current
ByteArrayBufferedData(ByteBuffer)ctor or a similarwrap(, offset, length)method also behave per their current javadoc, the result returned by thelength()method is incorrect. We wrapped a ByteBuffer of length 3 (see the last argument at the first line of code), so the length of the BufferedData object must also be 3, which currently it isn't because:and this code can only return the correct result if the offset of the buffer is zero, and also, only if the client code never modified the limit via the BufferedData APIs.
We even have unit tests that verify these odd results.
We need to revisit offsets/limits/lengths handling, fix bugs, update the unit tests, and then verify if the CN code still works and doesn't rely on the current incorrect behavior.