From 6e1cee654f53912406f4b7d67799127ee6811a88 Mon Sep 17 00:00:00 2001 From: Jatinder Date: Mon, 3 Mar 2014 17:16:59 +0530 Subject: [PATCH] [#2252] Fix bug where AppendableCharSequence private constructor does not set correct position --- .../io/netty/util/internal/AppendableCharSequence.java | 1 + .../io/netty/util/internal/AppendableCharSequenceTest.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/common/src/main/java/io/netty/util/internal/AppendableCharSequence.java b/common/src/main/java/io/netty/util/internal/AppendableCharSequence.java index b0c5e9a73b..32a5acd04e 100644 --- a/common/src/main/java/io/netty/util/internal/AppendableCharSequence.java +++ b/common/src/main/java/io/netty/util/internal/AppendableCharSequence.java @@ -31,6 +31,7 @@ public final class AppendableCharSequence implements CharSequence, Appendable { private AppendableCharSequence(char[] chars) { this.chars = chars; + pos = chars.length; } @Override diff --git a/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java b/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java index 3fca3e1569..81c5560bc3 100644 --- a/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java +++ b/common/src/test/java/io/netty/util/internal/AppendableCharSequenceTest.java @@ -57,6 +57,13 @@ public class AppendableCharSequenceTest { testAppendString0(new AppendableCharSequence(2)); } + @Test + public void testSubSequence() { + AppendableCharSequence master = new AppendableCharSequence(26); + master.append("abcdefghijlkmonpqrstuvwxyz"); + assertEquals(master.subSequence(0, 10).toString(), "abcdefghij"); + } + private static void testSimpleAppend0(AppendableCharSequence seq) { String text = "testdata"; for (int i = 0; i < text.length(); i++) {