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] java.util.ConcurrentModificationException #2358

Closed
chenxushaoxia opened this issue Mar 21, 2024 · 4 comments
Closed

[BUG] java.util.ConcurrentModificationException #2358

chenxushaoxia opened this issue Mar 21, 2024 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@chenxushaoxia
Copy link

问题描述

分析是List modules更改了。
只有多处地方调用了 JSON.parseObject同一个类,怀疑跟类加载器不一致相关。
代码片段,在多线程的环境下执行偶现ConcurrentModificationException。
Utils.useFunctionClassLoader();
T val = (T) JSON.parseObject(new String(bytes, StandardCharsets.UTF_8), this.type,
JSONReader.Feature.SupportAutoType, JSONReader.Feature.SupportClassForName);
Utils.useInstanceClassLoader();
return val;

报错堆栈信息。
java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.base/java.util.ArrayList$Itr.next(Unknown Source)
at com.alibaba.fastjson2.reader.ObjectReaderProvider.getFieldInfo(ObjectReaderProvider.java:675)
at com.alibaba.fastjson2.reader.ObjectReaderCreator.createFieldReader(ObjectReaderCreator.java:1234)
at com.alibaba.fastjson2.reader.ObjectReaderCreator.lambda$createFieldReaders$3(ObjectReaderCreator.java:1555)
at com.alibaba.fastjson2.util.BeanUtils.declaredFields(BeanUtils.java:307)
at com.alibaba.fastjson2.util.BeanUtils.declaredFields(BeanUtils.java:242)
at com.alibaba.fastjson2.reader.ObjectReaderCreator.createFieldReaders(ObjectReaderCreator.java:1549)
at com.alibaba.fastjson2.reader.ObjectReaderCreatorASM.createObjectReader(ObjectReaderCreatorASM.java:259)
at com.alibaba.fastjson2.reader.ObjectReaderProvider.getObjectReaderInternal(ObjectReaderProvider.java:854)
at com.alibaba.fastjson2.reader.ObjectReaderProvider.getObjectReader(ObjectReaderProvider.java:746)
at com.alibaba.fastjson2.JSONReader.getObjectReader(JSONReader.java:480)
at com.alibaba.fastjson2.reader.FieldReaderObject.getObjectReader(FieldReaderObject.java:70)
at com.alibaba.fastjson2.reader.ORG_6_3_JeDraftTransferVO.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ORG_3_9_JeDraftMsgVO.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:1002)
at com.huawei.dff.functions.runtime.serde.MsgpackSerDe.deserialize(MsgpackSerDe.java:33)
at com.huawei.dff.functions.runtime.serde.SerDeInstanceUtils.deserializeMessage(SerDeInstanceUtils.java:56)
at com.huawei.dff.functions.runtime.io.yuanrong.YuanRongSource.lambda$processDeseqialize$0(YuanRongSource.java:229)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.x.x]

重现步骤

如何操作可以重现该问题:

  1. 使用 xxx.xxx 方法
  2. 输入 ... 数据
  3. 出现 ... 错误
//可在此输入示例代码

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@chenxushaoxia chenxushaoxia added the bug Something isn't working label Mar 21, 2024
@wenshao wenshao added this to the 2.0.48 milestone Mar 21, 2024
@wenshao
Copy link
Member

wenshao commented Mar 21, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/ 问题已修复,请帮忙用2.0.48-SNAPSHOT验证,2.0.48正式版本预计在月末发布

@chenxushaoxia
Copy link
Author

再次验证没有出现该问题。但是有点疑问,在没有自定义配置的情况下吗,JSONFactory和ObjectReaderProvider这个应该是只会存在一个的,没有调用register和unregister方法为什么modules会变了?

@wenshao
Copy link
Member

wenshao commented Mar 22, 2024

我也很奇怪,我知道这样可以解问题,但没想明白原因

@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 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 fixed
Projects
None yet
Development

No branches or pull requests

2 participants