简体   繁体   English

运行时Kryo序列化器IllegalAccessError

[英]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.

相关问题 使用Kryo序列化任意Java对象(获取IllegalAccessError) - Serializing an arbitrary Java object with Kryo (getting IllegalAccessError) 使用 Kryo(自定义序列化程序)序列化对象 - Serialization of an object with Kryo (Custom Serializer) 如何在风暴中注册kryo序列化程序实例? - how to register kryo serializer instances in storm? Serializer - Kryo的速度,FlexJson等API /功能 - Serializer - speed of Kryo, API/functionality like FlexJson Flink Kryo 序列化器,因为找不到 Chill 序列化器 - Flink Kryo serializer because Chill serializer couldn't be found 为什么这个Scala代码会在运行时抛出IllegalAccessError? - Why does this Scala code throw IllegalAccessError at runtime? Spring Cloud数据流:注册新的自定义Kryo序列化器 - Spring Cloud dataflow: Register new custom kryo serializer Kryo序列化程序在底层Scala类WrappedArray上导致异常 - Kryo serializer causing exception on underlying Scala class WrappedArray java.lang.IllegalAccessError:org / apache / xml / serializer / ExtendedContentHandler - java.lang.IllegalAccessError: org/apache/xml/serializer/ExtendedContentHandler Kryo序列化导致致命的Java运行时错误与自定义对象 - Kryo serialization caused fatal java runtime error with custom objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM