Skip to content

Commit

Permalink
Clear Utf8ByteBufCharsetDecoder#splitCharBuffer once char is complete,
Browse files Browse the repository at this point in the history
…close #1357

Motivation:

When multiple non US-ASCII chars are split over several chunks,
Utf8ByteBufCharsetDecoder crashes with BufferOverflowException.

This happens because we don't clear the splitCharBuffer in-between and
only do so once decoding is done.

Modifications:

Clear Utf8ByteBufCharsetDecoder#splitCharBuffer once char is complete

Result:

No more BufferOverflowException
  • Loading branch information
slandelle committed Feb 14, 2017
1 parent b037426 commit 28e543c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Expand Up @@ -116,12 +116,13 @@ private void handleSplitCharBuffer(ByteBuffer nioBuffer, boolean endOfInput) thr
if (res.isError()) {
res.throwException();
}
splitCharBuffer.clear();
}
}

protected void decodePartial(ByteBuffer nioBuffer, boolean endOfInput) throws CharacterCodingException {
// deal with pending splitCharBuffer
if (splitCharBuffer != null && splitCharBuffer.position() > 0 && nioBuffer.hasRemaining()) {
if (splitCharBuffer.position() > 0 && nioBuffer.hasRemaining()) {
handleSplitCharBuffer(nioBuffer, endOfInput);
}

Expand Down
Expand Up @@ -20,7 +20,7 @@

import org.testng.annotations.Test;

public class ByteBufUtilsTest {
public class Utf8ByteBufCharsetDecoderTest {

@Test
public void testByteBuf2BytesHasBackingArray() {
Expand Down

0 comments on commit 28e543c

Please sign in to comment.