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

JSON.parseArray(String text, Class<T> type)方法指定Integer类型解析字符串导致OOM[BUG] #1717

Closed
gbhello opened this issue Aug 6, 2023 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@gbhello
Copy link

gbhello commented Aug 6, 2023

问题描述

使用JSON.parseArray(String text, Class type)方法解析字符串时,指定解析类型,在字符串是非指定类型数组时,会导致OOM

环境信息

请填写以下信息:

  • OS信息: [e.g.:WINDOWS10 4Core 2.3GHz 12 GB]
  • JDK信息: [e.g.: HotSpot "1.8.0_152"]
  • 版本信息:[e.g.:Fastjson2 2.0.38]

重现步骤

如下:

    public static void main(String args[]) {
        JSON.parseArray("[jia]", Integer.class);
    }

期待的正确结果

如之前的版本一样抛出解析异常,这个bug是新引入的,之前某个版本是可用的

相关日志输出

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:265)
	at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:239)
	at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:231)
	at java.util.ArrayList.add(ArrayList.java:462)
	at com.alibaba.fastjson2.JSONReader.readArray(JSONReader.java:2389)
	at com.alibaba.fastjson2.JSON.parseArray(JSON.java:2497)
	at com.box.Main1.main(Main1.java:27)

附加信息

fighting💪

@gbhello gbhello added the bug Something isn't working label Aug 6, 2023
kraity added a commit to kraity/fastjson2 that referenced this issue Aug 6, 2023
Signed-off-by: Kraity <kraty@krait.cn>
wenshao pushed a commit that referenced this issue Aug 6, 2023
Signed-off-by: Kraity <kraty@krait.cn>
@wenshao wenshao added this to the 2.0.39 milestone Aug 12, 2023
@wenshao
Copy link
Member

wenshao commented Aug 13, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.39-SNAPSHOT/
问题已修复,请帮忙用2.0.39-SNAPSHOT版本验证,2.0.39版本预计在8月27日前发布

@wenshao wenshao added the fixed label Aug 13, 2023
@wenshao
Copy link
Member

wenshao commented Aug 15, 2023

@wenshao wenshao closed this as completed Aug 15, 2023
@wendao8469759
Copy link

.... 真棒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants