Skip to content

Commit

Permalink
Backport fix #152 to 2.3 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 25, 2014
1 parent b806933 commit ea6d687
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit ea6d687

Please sign in to comment.