From eae9492c40e45bda8fb62b8f474ff86be55fb56d Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 24 Jun 2019 21:09:19 +0200 Subject: [PATCH] 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. --- buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java | 2 +- .../src/test/java/io/netty/buffer/EmptyByteBufTest.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java index afbb727e74..dac071ddd3 100644 --- a/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/EmptyByteBuf.java @@ -661,7 +661,7 @@ public final class EmptyByteBuf extends ByteBuf { @Override public CharSequence readCharSequence(int length, Charset charset) { checkLength(length); - return null; + return StringUtil.EMPTY_STRING; } @Override diff --git a/buffer/src/test/java/io/netty/buffer/EmptyByteBufTest.java b/buffer/src/test/java/io/netty/buffer/EmptyByteBufTest.java index acafca149f..c2d5764cb1 100644 --- a/buffer/src/test/java/io/netty/buffer/EmptyByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/EmptyByteBufTest.java @@ -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)); + } + }