Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ByteBufferSerializer produces unexpected results with a duplicated ByteBuffer and a position > 0 #2602

Closed
nastra opened this issue Jan 23, 2020 · 2 comments
Milestone

Comments

@nastra
Copy link

nastra commented Jan 23, 2020

The below test shows an issue where a duplicated ByteBuffer with a position > 0 is returning unexpected results:


public void testDuplicatedByteBufferWithCustomPosition() throws IOException
{
    final byte[] INPUT_BYTES = new byte[] { 1, 2, 3, 4, 5 };
    String exp = MAPPER.writeValueAsString(new byte[] { 3, 4, 5 });

    ByteBuffer bbuf = ByteBuffer.wrap(INPUT_BYTES);

    bbuf.position(2);
    ByteBuffer duplicated = bbuf.duplicate();

    assertEquals(exp, MAPPER.writeValueAsString(duplicated));
}
Expected :"AwQF"
Actual   :"AQIDBAU="

I tested this on commit 6e5e2b0 with the 2.10 branch.

nastra pushed a commit to nastra/jackson-databind that referenced this issue Jan 23, 2020
@nastra
Copy link
Author

nastra commented Jan 23, 2020

I also added a potential fix in #2603

@cowtowncoder
Copy link
Member

Thank you for reporting this, PR -- I hope to review this ASAP.

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

No branches or pull requests

2 participants