sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.59k stars 1.15k forks source link

jdk16环境下example报错 #633

Closed tsgmq closed 3 years ago

tsgmq commented 3 years ago

com.alipay.sofa.jraft.storage.log.SegmentFile 编译不通过 报错信息 java: 程序包 sun.nio.ch 不可见 (程序包 sun.nio.ch 已在模块 java.base 中声明, 但该模块未将它导出到未命名模块) image

killme2008 commented 3 years ago

应该是误用了,我们改下,您要有兴趣也可以提个修复 PR

fengjiachun commented 3 years ago

这个不是误用,只有 sun.nio.ch.DirectBuffer 有 address() api, DirectByteBuffer 只是包可见级别,外部无法访问

killme2008 commented 3 years ago

我的意思是可以改成反射的方式,不需要强依赖。

tsgmq commented 3 years ago

我的水平太菜了,不会改,麻烦修改下,我重新下载代码

tsgmq commented 3 years ago

Method method = this.buffer.getClass().getMethod("address"); final long address = (long)method.invoke(this.buffer);

fengjiachun commented 3 years ago

我下载个 zulu jdk16 看下怎么改好些

fengjiachun commented 3 years ago

我下载了 jdk16, 发现可以编译,你的报错是你的 idea 报错吧?

fengjiachun commented 3 years ago

本地执行一下 mvn clean compile 看看?如果可以编译,那么可能需要看看怎么修改一下你的 IDE 的配置

closess commented 3 years ago

跟你一样的问题,我用的jdk11,哈哈哈 解决方式:鼠标点击那个报红的区域,然后直接使用’ALT + Enter‘自动修复一下就可以了

tsgmq commented 3 years ago

java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String java.lang.StackTraceElement.classLoaderName accessible: module java.base does not “opens java.lang” to unnamed module @5cbc508c at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177) at java.base/java.lang.reflect.Field.setAccessible(Field.java:171) at com.caucho.hessian.io.JavaDeserializer.getFieldMap(JavaDeserializer.java:329) at com.caucho.hessian.io.JavaDeserializer.(JavaDeserializer.java:97) at com.caucho.hessian.io.StackTraceElementDeserializer.(StackTraceElementDeserializer.java:57) at com.caucho.hessian.io.SerializerFactory.(SerializerFactory.java:589) at com.alipay.remoting.serialization.HessianSerializer.(HessianSerializer.java:36) at com.alipay.remoting.serialization.SerializerManager.(SerializerManager.java:36) at com..CommandCodec.decodeCommand(CommandCodec.java:34) at com.jraft.snapshot.TradeSnapshotFile.load(TradeSnapshotFile.java:50) at com.**.jraft.statemachine.ArcTradingDraftPkgStateMachine.onSnapshotLoad(ArcTradingDraftPkgStateMachine.java:280) at com.alipay.sofa.jraft.core.FSMCallerImpl.doSnapshotLoad(FSMCallerImpl.java:652) at com.alipay.sofa.jraft.core.FSMCallerImpl.runApplyTask(FSMCallerImpl.java:398) at com.alipay.sofa.jraft.core.FSMCallerImpl.access$100(FSMCallerImpl.java:73) at com.alipay.sofa.jraft.core.FSMCallerImpl$ApplyTaskHandler.onEvent(FSMCallerImpl.java:148) at com.alipay.sofa.jraft.core.FSMCallerImpl$ApplyTaskHandler.onEvent(FSMCallerImpl.java:142) at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:137) at java.base/java.lang.Thread.run(Thread.java:831)

tsgmq commented 3 years ago
    <jraft-core-version>1.3.7</jraft-core-version>
killme2008 commented 3 years ago

@tsgmq 这个是你自己实现的吧 TradeSnapshotFile ,不是 jraft 的问题。

closess commented 3 years ago

我的jdk11也不能用。 这种方式应该是只有jdk8可以用,jdk8以上就不能用了。 你可以照我上面的方式修复一下就行了

tsgmq commented 3 years ago

感谢各位指点,主要是SerializerManager.getSerializer(SerializerManager.Hessian2).deserialize(content, clazz.getName()) 这个序列化的不行,本地解决了在服务器jdk16依然不行,我已经换成ProtoStuffSerializer来做序列化和反序列化,通过其他方式解决