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]JDK17 序列化异常 #2437

Closed
changeAtLater opened this issue Apr 12, 2024 · 3 comments
Closed

[BUG]JDK17 序列化异常 #2437

changeAtLater opened this issue Apr 12, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@changeAtLater
Copy link

changeAtLater commented Apr 12, 2024

问题描述

java.lang.IllegalAccessError: failed to access class java.util.concurrent.locks.ReentrantLock$Sync from class com.alibaba.fastjson2.writer.OWG_23_1_ReentrantLock (java.util.concurrent.locks.ReentrantLock$Sync is in module java.base of loader 'bootstrap'; com.alibaba.fastjson2.writer.OWG_23_1_ReentrantLock is in unnamed module of loader com.alibaba.fastjson2.util.DynamicClassLoader @38a01810)
at com.alibaba.fastjson2.writer.OWG_23_1_ReentrantLock.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.FieldWriterObject.write(FieldWriterObject.java:379)
at com.alibaba.fastjson2.writer.ObjectWriterAdapter.writeJSONB(ObjectWriterAdapter.java:205)
at com.alibaba.fastjson2.writer.OWG_22_6_ItemDataSource.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.writeJSONB(ObjectWriterImplMap.java:362)
at com.alibaba.fastjson2.writer.OWG_21_9_DynamicRoutingDataSource.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_20_3_Environment.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_19_53_Configuration.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_18_1_DefaultSqlSessionFactory.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_17_3_SqlSessionTemplate.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_16_3_MapperProxy.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_15_1_$Proxy211.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_14_2_SysDeptServiceImpl.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_13_1_OrganizationDataAscriptionCustomDataScope.writeJSONB(Unknown Source)
at com.alibaba.fastjson2.JSONB.toBytes(JSONB.java:1225)
at org.apache.dubbo.common.serialize.fastjson2.FastJson2ObjectOutput.writeObject(FastJson2ObjectOutput.java:115)

环境信息

请填写以下信息:

  • OS信息: window10
  • JDK信息: jdk-17.0.8
  • 版本信息:Fastjson2 2.0.43

重现步骤

如何操作可以重现该问题:使用dubbo 3.2.7版本出现的

@changeAtLater changeAtLater added the bug Something isn't working label Apr 12, 2024
@wenshao wenshao added this to the 2.0.49 milestone Apr 12, 2024
@wenshao wenshao added the fixed label Apr 12, 2024
@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.49
问题已修复,请帮忙用新版本验证

@wenshao wenshao closed this as completed Apr 14, 2024
@changeAtLater
Copy link
Author

changeAtLater commented Apr 15, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.49 问题已修复,请帮忙用新版本验证

rebuild一下项目就好了,我没法复现...

只能简单试了一下,好像没啥问题
以下是测试代码:

public static void main(String[] args) throws IOException {
  Bean bean = new Bean();
  byte[] bytes = JSONB.toBytes(bean, JSONWriter.Feature.WriteClassName,
          JSONWriter.Feature.FieldBased,
          JSONWriter.Feature.ReferenceDetection,
          JSONWriter.Feature.WriteNulls,
          JSONWriter.Feature.NotWriteDefaultValue,
          JSONWriter.Feature.NotWriteHashMapArrayListClassName,
          JSONWriter.Feature.WriteNameAsSymbol);

  System.out.println(Objects.nonNull(bytes));

  Bean bean1 = JSONB.parseObject(bytes, Bean.class,
          JSONReader.Feature.UseDefaultConstructorAsPossible,
          JSONReader.Feature.UseNativeObject,
          JSONReader.Feature.IgnoreAutoTypeNotMatch,
          JSONReader.Feature.FieldBased);

  System.out.println(bean1.lock);
}

public static class Bean {
  public Lock lock = new ReentrantLock();
}

2.0.43版本测试情况:

Exception in thread "main" java.lang.IllegalAccessError: failed to access class java.util.concurrent.locks.ReentrantLock$Sync from class com.alibaba.fastjson2.writer.OWG_2_1_ReentrantLock (java.util.concurrent.locks.ReentrantLock$Sync is in module java.base of loader 'bootstrap'; com.alibaba.fastjson2.writer.OWG_2_1_ReentrantLock is in unnamed module of loader com.alibaba.fastjson2.util.DynamicClassLoader @271053e1)
	at com.alibaba.fastjson2.writer.OWG_2_1_ReentrantLock.writeJSONB(Unknown Source)
	at com.alibaba.fastjson2.writer.OWG_1_1_Bean.writeJSONB(Unknown Source)
	at com.alibaba.fastjson2.JSONB.toBytes(JSONB.java:1225)

2.0.49版本测试情况:

true
java.util.concurrent.locks.ReentrantLock@4f9a3314[Unlocked]

@changeAtLater
Copy link
Author

https://github.com/alibaba/fastjson2/releases/tag/2.0.49 问题已修复,请帮忙用新版本验证

如果lock是外部传入的话,序列化再反序列化,lock就没了,算不算问题?

public static void main(String[] args) throws IOException {
    Bean bean = new Bean();
    bean.lock = new ReentrantLock();
    bean.lock.lock();
    byte[] bytes = JSONB.toBytes(bean, JSONWriter.Feature.WriteClassName,
            JSONWriter.Feature.FieldBased,
            JSONWriter.Feature.ReferenceDetection,
            JSONWriter.Feature.WriteNulls,
            JSONWriter.Feature.NotWriteDefaultValue,
            JSONWriter.Feature.NotWriteHashMapArrayListClassName,
            JSONWriter.Feature.WriteNameAsSymbol);
    System.out.println(Objects.nonNull(bytes));
    Bean bean1 = JSONB.parseObject(bytes, Bean.class,
            JSONReader.Feature.UseDefaultConstructorAsPossible,
            JSONReader.Feature.UseNativeObject,
            JSONReader.Feature.IgnoreAutoTypeNotMatch,
            JSONReader.Feature.FieldBased);
    System.out.println(bean1.lock);
}

public static class Bean {
    public Lock lock;
}

测试结果:

true
null

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