diff --git a/release-notes/VERSION b/release-notes/VERSION index 7dee39fe50..ee5ee91ae1 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -1,12 +1,13 @@ Project: jackson-core -Version: 2.3.4 (17-Jul-2014) +Version: 2.3.5 (xx-xxx-2014) -No changes. +#152: Exception for property names longer than 256k ------------------------------------------------------------------------ === History: === ------------------------------------------------------------------------ +2.3.4 (17-Jul-2014) 2.3.3 (10-Apr-2014) No changes since 2.3.2. diff --git a/src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java b/src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java index 9ba08e5f8c..dde3a87162 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java +++ b/src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java @@ -575,8 +575,11 @@ public char[] expandCurrentSegment() final char[] curr = _currentSegment; // Let's grow by 50% final int len = curr.length; - // Must grow by at least 1 char, no matter what - int newLen = (len == MAX_SEGMENT_LEN) ? (MAX_SEGMENT_LEN+1) : Math.min(MAX_SEGMENT_LEN, len + (len >> 1)); + int newLen = len + (len >> 1); + // but above intended maximum, slow to increase by 25% + if (newLen > MAX_SEGMENT_LEN) { + newLen = len + (len >> 2); + } return (_currentSegment = ArraysCompat.copyOf(curr, newLen)); } diff --git a/src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java b/src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java index c4be4cd09f..543a38675d 100644 --- a/src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java +++ b/src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java @@ -62,4 +62,19 @@ public void testLongAppend() assertEquals(len+2, tb.size()); assertEquals(EXP, tb.contentsAsString()); } + + // [Core#152] + public void testExpand() + { + TextBuffer tb = new TextBuffer(new BufferRecycler()); + char[] buf = tb.getCurrentSegment(); + + while (buf.length < 500 * 1000) { + char[] old = buf; + buf = tb.expandCurrentSegment(); + if (old.length >= buf.length) { + fail("Expected buffer of "+old.length+" to expand, did not, length now "+buf.length); + } + } + } }