fastjson2
fastjson2 copied to clipboard
[BUG] OutOfMemoryError in JSON.parseArray
问题描述
以下代码使用fastjson2和fastjson 1.2.83会抛出异常,使用fastjson 2.0.50 会导致内存溢出。
环境信息
- OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
- JDK信息: [Openjdk 17.0.6]
- 版本信息:[Fastjson 2.0.50]
重现步骤
import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;
import java.util.List;
public class Issue1184Mutated_547 {
@Test
public void test() {
final String source = "[{\"code\":\"face_1\",\"disc\":\"人脸\"}]";
List<VerifyDevice> devices = JSON.parseArray(source, VerifyDevice.class);
}
@Test
public void test_fj() {
final String source = "[{\"code\":\"face_1\",\"disc\":\"人脸\"}]";
List<VerifyDevice> devices = com.alibaba.fastjson.JSON.parseArray(source, VerifyDevice.class);
}
public enum VerifyDevice {
FACE_DETECT("face_1", "人脸"),
IC_CARD("ic_2", "IC卡");
private final String code;
private final String disc;
VerifyDevice(String code, String disc) {
this.code = code;
this.disc = disc;
}
public String getCode() {
return code;
}
public String getDisc() {
return disc;
}
}
}
相关日志输出
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.base/java.util.Arrays.copyOf(Arrays.java:3512) at java.base/java.util.Arrays.copyOf(Arrays.java:3481) at java.base/java.util.ArrayList.grow(ArrayList.java:237) at java.base/java.util.ArrayList.grow(ArrayList.java:244) at java.base/java.util.ArrayList.add(ArrayList.java:454) at java.base/java.util.ArrayList.add(ArrayList.java:467) at com.alibaba.fastjson2.reader.ObjectReaderImplList.readObject(ObjectReaderImplList.java:643) at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:1803) at com.alibaba.fastjson.JSON.parseArray(JSON.java:2042) at Issue1184Mutated_547.test_fj(Issue1184Mutated_547.java:19)