| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Nice catch! Seems this is a tricky area of the code, several other bugs due to not calling duplicate() were recently fixed 😬
Sorry, something went wrong.
| } | ||
|
|
||
| return value.order(ByteOrder.LITTLE_ENDIAN).getShort(offset); | ||
| return value.duplicate().order(ByteOrder.LITTLE_ENDIAN).getShort(offset); |
There was a problem hiding this comment.
Can we do something similar as ByteArraySliceBackedBinary and avoid duplicating?
return (short) (((value.get(offset + 1) & 0xff) << 8) | (value.get(offset) & 0xff));
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Rationale for this change
ByteBufferBackedBinary.get2BytesLittleEndian() currently changes the byte order of its backing ByteBuffer to little endian. Because the buffer can be caller-owned, reading the binary can unexpectedly affect subsequent reads through the original buffer.
What changes are included in this PR?
Read the short through a duplicate buffer so the original buffer order remains unchanged.
Are these changes tested?
Yes. The regression test verifies the returned value and preserves the original big-endian order for heap, direct, and read-only buffers. The complete TestBinary class and Spotless check pass.
Are there any user-facing changes?
Calling get2BytesLittleEndian() no longer changes the order of the caller-owned backing buffer.