Skip to content

Commit 6c4f04e

Browse files
committed
Fixed #49
1 parent 248576e commit 6c4f04e

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/DeferredMap.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ private final int _newSize(int size)
149149
if (size < 200) {
150150
return size+size;
151151
}
152+
// note: MUST ensure it's divisible by two (that is, last bit is 0), because
153+
// always adding values in pairs, but checking size before add
152154
if (size < 2000) {
153-
return size + (size>>1);
155+
return size + ((size>>1) & ~1);
154156
}
155-
return size + (size>>2);
157+
return size + ((size>>2) & ~1);
156158
}
157159

158160
protected Map<Object,Object> _buildMap(int expSize)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fasterxml.jackson.jr.ob;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.jr.ob.JSON;
6+
7+
// for [jackson-jr#49], where `DeferredMap` explodes
8+
public class ReadMapTest extends TestBase
9+
{
10+
public void testIssues49() throws Exception
11+
{
12+
for (int i : new int[] { 7, 99, 513, 1099, 3003, 5005, 10001, 90003, 111111 }) {
13+
testLargeJson(i);
14+
}
15+
}
16+
17+
private void testLargeJson(int size) throws Exception {
18+
Map<String, Object> map = new HashMap<String, Object>();
19+
for (int i = 0; i < size; i++) {
20+
map.put("" + i, new HashMap<String, Object>());
21+
}
22+
String json = JSON.std.asString(map);
23+
Map<?,?> result = JSON.std.mapFrom(json);
24+
assertNotNull(result);
25+
assertEquals(size, result.size());
26+
}
27+
}

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-jr
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.7.9 (not yet released)
8+
9+
#49: ArrayIndexOutOfBoundsException when parsing large Map
10+
(reported by Michael J)
11+
712
2.7.8 (26-Sep-2016)
813
2.7.7 (27-Aug-2016)
914
2.7.6 (23-Jul-2016)

0 commit comments

Comments
 (0)