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

1.2.83 版本使用 JSON.parseObject 方法转换字符串时,会报OOM #4481

Open
ouxuyong opened this issue Feb 19, 2024 · 8 comments
Open

Comments

@ouxuyong
Copy link

fastjson 版本 :

com.alibaba
fastjson
1.2.83

复现bug代码如下:
List<Map<String,Object>> map = JSON.parseObject("[""]",new TypeReference<>(){});

@LSL1618
Copy link

LSL1618 commented Feb 27, 2024

[""]格式不太对,[{}]这样才对,TypeReference要指定泛型吧。

@ouxuyong
Copy link
Author

[""]格式不太对,[{}]这样才对,TypeReference要指定泛型吧。

格式不对你可以报错,报格式不正确。而你报个OOM?你觉得合理吗?

@LSL1618
Copy link

LSL1618 commented Feb 28, 2024

[""]格式不太对,[{}]这样才对,TypeReference要指定泛型吧。

格式不对你可以报错,报格式不正确。而你报个OOM?你觉得合理吗?

这样一行代码,怎么可能导致OOM!TypeReference不指定泛型,连编译都过不了,就别说运行了。
我指定泛型之后,编译通过,运行正常,你应该找错原因了
List<Map<String,Object>> map = JSON.parseObject("[\"\"]",new TypeReference<ArrayList>(){});

@ccfish86
Copy link

ccfish86 commented Mar 8, 2024

[""]格式不太对,[{}]这样才对,TypeReference要指定泛型吧。

格式不对你可以报错,报格式不正确。而你报个OOM?你觉得合理吗?

这样一行代码,怎么可能导致OOM!TypeReference不指定泛型,连编译都过不了,就别说运行了。 我指定泛型之后,编译通过,运行正常,你应该找错原因了 List<Map<String,Object>> map = JSON.parseObject("[\"\"]",new TypeReference<ArrayList>(){});

你试试下面这个,确定是比较有问题的。

var map = JSON.parseObject("[\"\"]", new TypeReference<ArrayList<HashMap<String, Object>>>() {
        });

@StruggleYang
Copy link

image 问题确实存在,有人知道这个 BUG 什么时候修复了吗? ----------- The problem does exist, does anyone know when this bug will be fixed?

@StruggleYang
Copy link

image 问题确实存在,有人知道这个 BUG 什么时候修复了吗? ----------- The problem does exist, does anyone know when this bug will be fixed?

虽然复现了,楼主写法好像不对,泛型应该是这样写? List<String> map = JSON.parseObject("[\"\"]",new TypeReference<List<String>>(){});

@swapdewalkar
Copy link

2.0.41 已修复

@LSL1618
Copy link

LSL1618 commented Apr 1, 2024

image 问题确实存在,有人知道这个 BUG 什么时候修复了吗? ----------- The problem does exist, does anyone know when this bug will be fixed?

虽然复现了,楼主写法好像不对,泛型应该是这样写? List<String> map = JSON.parseObject("[\"\"]",new TypeReference<List<String>>(){});

应该是复杂泛型(多层套娃)导致的,简单泛型是不会有问题的。

// 简单泛型ArrayList正常
ArrayList<HashMap<String, Object>> map = JSON.parseObject("[\"\"]", new TypeReference<ArrayList>(){});
// 复杂泛型ArrayList<HashMap<String, Object>>会报异常
ArrayList<HashMap<String, Object>> map = JSON.parseObject("[\"\"]", new TypeReference<ArrayList<HashMap<String, Object>>>(){});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants