0
votes

I am serializing with:

    private byte[] serialize()
{
    KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
    Kryo kryo = pool.borrow();
    Output output = new Output(0, 1024);
    kryo.writeClassAndObject(output, readsSetNode);
    byte[] bytes = output.toBytes();
    output.close();
    pool.release(kryo);
    return bytes;
}

and deserializing:

KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
        Kryo kryo = pool.borrow();

        Input input = new Input(bytes);
        HashMap<NodeStorage, NodeStorage> deserialized = (HashMap<NodeStorage, NodeStorage>) kryo.readClassAndObject(input);
        input.close();

        pool.release(kryo);

The hashmap "deserialized" contains the object correctly but unfortunately the log is spammed with a buffer underflow exception: It seems this only happens when I try to debug the application. Does this cause any problems or is that behaviour normal?

com.esotericsoftware.kryo.KryoException: Buffer underflow. at com.esotericsoftware.kryo.io.Input.require(Input.java:199) at com.esotericsoftware.kryo.io.Input.readVarInt(Input.java:373) at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:127) at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:693) at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:804) at main.java.com.bag.server.TestServer.appExecuteUnordered(TestServer.java:78) at bftsmart.tom.server.defaultservices.DefaultRecoverable.executeUnordered(DefaultRecoverable.java:417) at bftsmart.tom.ServiceReplica.receiveReadonlyMessage(ServiceReplica.java:214) at bftsmart.tom.core.DeliveryThread.deliverUnordered(DeliveryThread.java:289) at bftsmart.tom.core.TOMLayer.requestReceived(TOMLayer.java:290) at bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.channelRead0(NettyClientServerCommunicationSystemServerSide.java:184) at bftsmart.communication.client.netty.NettyClientServerCommunicationSystemServerSide.channelRead0(NettyClientServerCommunicationSystemServerSide.java:61) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:277) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:264) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)

1
Not sure if this is it, but I'd try constructing your Output with a ByteArrayOutputStream.Max

1 Answers

0
votes

I had meet the same issue, you should modify your serialize function like this:

    private byte[] serialize()
{
    KryoPool pool = new KryoPool.Builder(factory).softReferences().build();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Kryo kryo = pool.borrow();
    Output output = new Output(byteArrayOutputStream);
    kryo.writeClassAndObject(output, readsSetNode);
    output.close();
    pool.release(kryo);
    byte[] bytes = byteArrayOutputStream.toByteArray();;
    return bytes;
}