Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

在jdk17里使用fastjson反序列化Exception时,会抛出下面的异常,IgnoreErrorGetter配置不生效 #4077

Open
hengyunabc opened this issue Apr 18, 2022 · 4 comments
Assignees
Labels
Milestone

Comments

@hengyunabc
Copy link
Contributor

java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.Throwable java.lang.Throwable.cause accessible: module java.base does not "opens java.lang" to unnamed module @2dc96ada
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at com.alibaba.fastjson.util.TypeUtils.setAccessible(TypeUtils.java:2510)
        at com.alibaba.fastjson.util.FieldInfo.<init>(FieldInfo.java:196)
        at com.alibaba.fastjson.util.FieldInfo.<init>(FieldInfo.java:115)
        at com.alibaba.fastjson.util.TypeUtils.computeGetters(TypeUtils.java:2093)
        at com.alibaba.fastjson.util.TypeUtils.buildBeanInfo(TypeUtils.java:1819)
        at com.alibaba.fastjson.util.TypeUtils.buildBeanInfo(TypeUtils.java:1759)
        at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:564)
        at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:440)
        at com.alibaba.fastjson.serializer.JSONSerializer.getObjectWriter(JSONSerializer.java:448)
        at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:309)
        at com.alibaba.fastjson.JSON.toJSONString(JSON.java:687)
        at com.alibaba.fastjson.JSON.toJSONString(JSON.java:676)

com.alibaba.fastjson.util.TypeUtils 里的 catch AccessControlException 感觉要改为 Throwable,因为在jdk 17里抛出的异常是 java.lang.reflect.InaccessibleObjectException

    static void setAccessible(AccessibleObject obj){
        if(!setAccessibleEnable){
            return;
        }
        if(obj.isAccessible()){
            return;
        }
        try{
            obj.setAccessible(true);
        } catch(AccessControlException error){
            setAccessibleEnable = false;
        }
    }
hengyunabc added a commit to hengyunabc/fastjson that referenced this issue Apr 18, 2022
@wenshao wenshao modified the milestone: 1.2.80 Apr 18, 2022
@wenshao wenshao self-assigned this Apr 18, 2022
@wenshao wenshao added the bug label Apr 18, 2022
@wenshao wenshao added this to the 1.2.81 milestone Apr 18, 2022
wenshao added a commit that referenced this issue Apr 20, 2022
fix InaccessibleObjectException in jdk17. #4077
wenshao added a commit that referenced this issue Apr 20, 2022
Revert "fix InaccessibleObjectException in jdk17. #4077"
hengyunabc added a commit to hengyunabc/fastjson that referenced this issue Apr 20, 2022
wenshao added a commit that referenced this issue Apr 20, 2022
fix InaccessibleObjectException in jdk17. #4077
@fyeeme
Copy link

fyeeme commented Nov 14, 2023

项目升级JDK 17,未修复 fastjson,碰到了同样的问题

@zhangshuhua
Copy link

项目升级JDK 17,未修复 fastjson,碰到了同样的问题

请教一下,这个问题怎么处理,我升级到最新的1.2.83还是有一样的问题

@fyeeme
Copy link

fyeeme commented Mar 4, 2024

@zhangshuhua 最新的版本已经修复了该问题,如果你升级了,还是碰到了同样的问题,看看是不是有其他的依赖低版本fastjson

@chenzz
Copy link

chenzz commented Jun 4, 2024

@zhangshuhua 最新的版本已经修复了该问题,如果你升级了,还是碰到了同样的问题,看看是不是有其他的依赖低版本fastjson

1.2.83还是有同样的问题。。

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

No branches or pull requests

6 participants
@wenshao @hengyunabc @chenzz @fyeeme @zhangshuhua and others