Skip to content

MessageBuffer.sliceAsByteBuffer() method has old values after MessageBufferPacker.clear() #458

Description

@isopov

Consider the following code:

MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
packer.packInt(1);
packer.flush();
packer.clear();

packer.packInt(2);

MessageBuffer buffer = packer.toBufferList().get(0);
System.out.println(Arrays.toString(packer.toByteArray()));
System.out.println(Arrays.toString(buffer.toByteArray()));
byte[] array = Arrays.copyOf(buffer.sliceAsByteBuffer().array(), buffer.size());
System.out.println(Arrays.toString(array));

I expected it to print the same value 3 times, but its output is:

[2]
[2]
[1]

AFAIU there is a bug somewhere - in clear() implementation or somewhere else. I think it is in clear() because removing flush() produces the following output:

[1, 2]
[1, 2]
[1, 2]

It seems that clear() has no effect at all in this case.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions