Skip to content

Commit ea6d687

Browse files
committed
Backport fix #152 to 2.3 branch
1 parent b806933 commit ea6d687

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

release-notes/VERSION

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
Project: jackson-core
2-
Version: 2.3.4 (17-Jul-2014)
2+
Version: 2.3.5 (xx-xxx-2014)
33

4-
No changes.
4+
#152: Exception for property names longer than 256k
55

66
------------------------------------------------------------------------
77
=== History: ===
88
------------------------------------------------------------------------
99

10+
2.3.4 (17-Jul-2014)
1011
2.3.3 (10-Apr-2014)
1112

1213
No changes since 2.3.2.

src/main/java/com/fasterxml/jackson/core/util/TextBuffer.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,11 @@ public char[] expandCurrentSegment()
575575
final char[] curr = _currentSegment;
576576
// Let's grow by 50%
577577
final int len = curr.length;
578-
// Must grow by at least 1 char, no matter what
579-
int newLen = (len == MAX_SEGMENT_LEN) ? (MAX_SEGMENT_LEN+1) : Math.min(MAX_SEGMENT_LEN, len + (len >> 1));
578+
int newLen = len + (len >> 1);
579+
// but above intended maximum, slow to increase by 25%
580+
if (newLen > MAX_SEGMENT_LEN) {
581+
newLen = len + (len >> 2);
582+
}
580583
return (_currentSegment = ArraysCompat.copyOf(curr, newLen));
581584
}
582585

src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java

+15
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,19 @@ public void testLongAppend()
6262
assertEquals(len+2, tb.size());
6363
assertEquals(EXP, tb.contentsAsString());
6464
}
65+
66+
// [Core#152]
67+
public void testExpand()
68+
{
69+
TextBuffer tb = new TextBuffer(new BufferRecycler());
70+
char[] buf = tb.getCurrentSegment();
71+
72+
while (buf.length < 500 * 1000) {
73+
char[] old = buf;
74+
buf = tb.expandCurrentSegment();
75+
if (old.length >= buf.length) {
76+
fail("Expected buffer of "+old.length+" to expand, did not, length now "+buf.length);
77+
}
78+
}
79+
}
6580
}

0 commit comments

Comments
 (0)