问题
项目启动后,调用服务时产生报错如下:
java.lang.reflect.InaccessibleObjectException: Unable to make field final int java.math.BigInteger.signum accessible: module java.base does not "opens java.math" to unnamed module @3098cf3b
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.com.caucho.hessian.io.JavaDeserializer.getFieldMap(JavaDeserializer.java:340)
at com.alibaba.com.caucho.hessian.io.JavaDeserializer.<init>(JavaDeserializer.java:80)
at com.alibaba.com.caucho.hessian.io.BigIntegerDeserializer.<init>(BigIntegerDeserializer.java:25)
at com.alibaba.com.caucho.hessian.io.SerializerFactory.<clinit>(SerializerFactory.java:142)
at org.apache.dubbo.common.serialize.hessian2.Hessian2FactoryManager.createDefaultSerializerFactory(Hessian2FactoryManager.java:81)
at org.apache.dubbo.common.serialize.hessian2.Hessian2FactoryManager.createSerializerFactory(Hessian2FactoryManager.java:77)
at org.apache.dubbo.common.serialize.hessian2.Hessian2FactoryManager.getSerializerFactory(Hessian2FactoryManager.java:62)
at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectInput.<init>(Hessian2ObjectInput.java:46)
at org.apache.dubbo.common.serialize.hessian2.Hessian2Serialization.deserialize(Hessian2Serialization.java:66)
原因
从 Java 9 开始,由于引入了模块化系统,Java的类库中一些内部实现详情被封装起来,不再对外部代码开放。InaccessibleObjectException
是当应用试图访问类、字段、方法或者构造器的某个成员,但是当前的 Java 模块化系统策略不允许访问时,会抛出的错误。
相关 Issue :dubbo 3.0.6 对jdk17的支持不完善 · Issue #9868 · apache/dubbo (github.com)
解决
在Java命令行启动参数中添加 --add-opens java.base/java.math=ALL-UNNAMED
来显式打开 java.math
包给所有未命名的包