Skip to content

Commit 2908767

Browse files
committed
ByteBufferInput should not be affected when given ByteBuffer's position is modified
1 parent b1db42d commit 2908767

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

msgpack-core/src/main/java/org/msgpack/core/buffer/ByteBufferInput.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ public class ByteBufferInput
3131

3232
public ByteBufferInput(ByteBuffer input)
3333
{
34-
this.input = checkNotNull(input, "input ByteBuffer is null");
34+
this.input = checkNotNull(input, "input ByteBuffer is null").slice();
3535
}
3636

3737
/**
38-
* Reset buffer. This method doesn't close the old resource.
38+
* Reset buffer.
3939
*
4040
* @param input new buffer
41-
* @return the old resource
41+
* @return the old buffer
4242
*/
4343
public ByteBuffer reset(ByteBuffer input)
4444
{
4545
ByteBuffer old = this.input;
46-
this.input = input;
46+
this.input = checkNotNull(input, "input ByteBuffer is null").slice();
4747
isRead = false;
4848
return old;
4949
}
@@ -55,8 +55,9 @@ public MessageBuffer next()
5555
return null;
5656
}
5757

58+
MessageBuffer b = MessageBuffer.wrap(input);
5859
isRead = true;
59-
return MessageBuffer.wrap(input);
60+
return b;
6061
}
6162

6263
@Override

0 commit comments

Comments
 (0)