[英]Kryo Serializer IllegalAccessError at runtime
We are trying to use Kryo Serializer to serialize our application object to push them in a kafka stream. 我们正在尝试使用Kryo序列化程序来序列化我们的应用程序对象,以将其推送到kafka流中。
The serialization code has 序列化代码具有
private ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.addDefaultSerializer(MyApp.class, new MyAppKyroSerializer());
return kryo;
};
};
The serialize method is: 序列化方法是:
@Override
public byte[] serialize(String topic, MyApp data) {
ByteBufferOutput output = new ByteBufferOutput(100);
kryos.get().writeObject(output, data);
return output.toBytes();
}
While executing the Application we are getting the following IllegalAccessError: 在执行应用程序时,我们得到以下IllegalAccessError:
Exception in thread "main" java.lang.IllegalAccessError: tried to access field com.esotericsoftware.kryo.io.Output.capacity from class com.esotericsoftware.kryo.io.ByteBufferOutput
at com.esotericsoftware.kryo.io.ByteBufferOutput.<init>(ByteBufferOutput.java:66)
at com.esotericsoftware.kryo.io.ByteBufferOutput.<init>(ByteBufferOutput.java:58)
at com.mycom.serializer.MyAppSerializer.serialize(MyAppSerializer.java:43)
This is strange because ByteBufferOutput extends Output and capacity is a protected field. 这很奇怪,因为ByteBufferOutput扩展了Output并且容量是一个受保护的字段。
public byte[] serialize(String topic, Myapp data) {
Output output = new Output(100);
kryos.get().writeObject(output, data);
return output.toBytes();
}
Try this i think this will work.. 试试这个,我认为这会工作..
As it said in Java Documentation for IllegalAccessError
: 如Java文档中对
IllegalAccessError
:
Normally, this error is caught by the compiler;
通常,此错误由编译器捕获; this error can only occur at run time if the definition of a class has incompatibly changed.
如果类的定义发生了不兼容的更改,则只有在运行时才会发生此错误。
So suggestion would be to check if all Kryo libs (in your project) are compliant with each other and belong to one-version of Kryo. 因此建议是检查所有Kryo库(在您的项目中)是否相互兼容并且属于Kryo的一个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.