Skip to content

MessageBuffer.wrap(ByteBuffer) is broken #188

@superfell

Description

@superfell

the MessageBuffer constructor that takes a ByteBuffer behaves wrongly if the supplied byte buffer only occupies a subset of the backing array, it ignores the bytebuffer subset, and just looks at the entire backing array. e.g. this test demonstrates the problem

@test
public void testWrappedByteBuffer() {
byte [] d = {10,11,12,13,14,15,16,17,18,19};
ByteBuffer subset = ByteBuffer.wrap(d, 2, 2);
MessageBuffer mb = MessageBuffer.wrap(subset);
Assert.assertEquals(12, mb.getByte(0)); // fails returns 10
Assert.assertEquals(2, mb.size()); // fails return 10
}

The code seems to assume that ByteBuffer.array() returns an array of just the current Buffer contents, but in fact it returns the entire backing array.

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