Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] OutOfMemoryError in JSON.parseArray #2591

Open
Cooper-Zhong opened this issue May 17, 2024 · 0 comments
Open

[BUG] OutOfMemoryError in JSON.parseArray #2591

Cooper-Zhong opened this issue May 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Cooper-Zhong
Copy link

问题描述

以下代码使用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)

@Cooper-Zhong Cooper-Zhong added the bug Something isn't working label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant