fastjson OutOfMemoryError on JSON.parseObject() String with ASCII symbols

7d7tgy0s  于 4个月前  发布在  SEO
关注(0)|答案(1)|浏览(148)

Description:

OutOfMemoryError exception on JSON.parseObject() String containign ASCII symbols (SUB/0x1a).

Minimal reproducible example:

import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.nio.charset.StandardCharsets;

public class Test {
           public static void main(String[] args) throws Exception {
                  byte[] bytes = {0x1a, 0x5b};
                  String s = new String(bytes, StandardCharsets.US_ASCII);
                  JSON.parseObject(s, new TypeReference<ArrayList<Integer>>() {});
           }
}

Log:

Exception in thread "main" com.alibaba.fastjson.JSONException: Java heap space
        at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:710)
        at com.alibaba.fastjson.JSON.parseObject(JSON.java:394)
        at com.alibaba.fastjson.JSON.parseObject(JSON.java:362)
        at com.alibaba.fastjson.JSON.parseObject(JSON.java:276)
        at Test.main(Test.java:11)
Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:3210)
        at java.util.Arrays.copyOf(Arrays.java:3181)
        at java.util.ArrayList.grow(ArrayList.java:267)
        at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:241)
        at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:233)
        at java.util.ArrayList.add(ArrayList.java:464)
        at com.alibaba.fastjson.parser.DefaultJSONParser.parseArray(DefaultJSONParser.java:794)
        at com.alibaba.fastjson.serializer.CollectionCodec.deserialze(CollectionCodec.java:132)
        at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:705)
        ... 4 more

相关问题