Skip to content

MINOR: Preserve ByteBuffer order in little-endian reads - #3702

Open
fallintoplace wants to merge 1 commit into
apache:masterfrom
fallintoplace:fix-binary-little-endian-buffer-order
Open

MINOR: Preserve ByteBuffer order in little-endian reads#3702
fallintoplace wants to merge 1 commit into
apache:masterfrom
fallintoplace:fix-binary-little-endian-buffer-order

Conversation

@fallintoplace

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant