EmptyByteBuf.getCharSequence(0,...) must return empty String (#9272)

Motivation:

At the moment EmptyByteBuf.getCharSequence(0,...) will return null while it must return a "".

Modifications:

- Let EmptyByteBuf.getCharSequence(0,...) return ""
- Add unit test

Result:

Fixes https://github.com/netty/netty/issues/9271.
This commit is contained in:
Norman Maurer 2019-06-24 21:09:19 +02:00 committed by GitHub
parent 097f422198
commit 265c745d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -684,7 +684,7 @@ public final class EmptyByteBuf extends ByteBuf {
@Override
public CharSequence readCharSequence(int length, Charset charset) {
checkLength(length);
return null;
return StringUtil.EMPTY_STRING;
}
@Override

View File

@ -14,6 +14,7 @@
* under the License.
*/package io.netty.buffer;
import io.netty.util.CharsetUtil;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
@ -93,4 +94,11 @@ public class EmptyByteBufTest {
assertTrue(emptyAbstract.release());
assertFalse(empty.release());
}
@Test
public void testGetCharSequence() {
EmptyByteBuf empty = new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT);
assertEquals("", empty.readCharSequence(0, CharsetUtil.US_ASCII));
}
}