question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom codec not working after version 3.10.0

See original GitHub issue

We have been using a custom KryoCodec(overriding the built in one) for a while but after version 3.10.0 this no longer works. The change that affects us are introduced by the following commit: https://github.com/redisson/redisson/commit/37b58db7bcc2bdf586e3ce2e55a37803fcd545fd

I’ve spent a little bit of time looking into what’s going on and it looks like there are issues regarding classloading since we got all sorts of exceptions now, especially lots of com.esotericsoftware.kryo.KryoException: Unable to find class on classes that we have been serializing without problems til now. The root cause is of course java.lang.ClassNotFoundException:x.y.z

I’ve attached the relevant code with the working and non working solution:

Working:

public class KryoCodec extends org.redisson.codec.KryoCodec {

    private static class KryoPoolImpl extends org.redisson.codec.KryoCodec.KryoPoolImpl {

        KryoPoolImpl(List<Class<?>> classes, ClassLoader classLoader) {
            super(classes, classLoader);
        }

        @Override
        protected Kryo createInstance() {
            Kryo kryo = super.createInstance();
            kryo.setReferences(true);
            UnmodifiableCollectionsSerializer.registerSerializers(kryo);
            kryo.setInstantiatorStrategy(
                    new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())
            );
            return kryo;
        }

    }

    public KryoCodec() {
        this(Collections.emptyList());
    }

    public KryoCodec(ClassLoader classLoader) {
        this(Collections.emptyList(), classLoader);
    }

    public KryoCodec(List<Class<?>> classes) {
        this(classes, null);
    }

    public KryoCodec(List<Class<?>> classes, ClassLoader classLoader) {
        this(new KryoPoolImpl(classes, classLoader));
    }

    public KryoCodec(KryoPoolImpl kryoPool) {
        super(kryoPool);
    }

}

Non-working:

public class KryoCodec extends org.redisson.codec.KryoCodec {

    private final KryoPoolImpl kryoPool;

    private static class KryoPoolImpl extends org.redisson.codec.KryoCodec.KryoPoolImpl {

        KryoPoolImpl(List<Class<?>> classes, ClassLoader classLoader) {
            super(classes, classLoader);
        }

        @Override
        protected Kryo createInstance() {
            Kryo kryo = super.createInstance();
            kryo.setReferences(true);
            UnmodifiableCollectionsSerializer.registerSerializers(kryo);
            kryo.setInstantiatorStrategy(
                    new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())
            );
            return kryo;
        }

    }

    public KryoCodec() {
        this(Collections.emptyList());
    }

    public KryoCodec(ClassLoader classLoader) {
        this(Collections.emptyList(), classLoader);
    }

    public KryoCodec(ClassLoader classLoader, KryoCodec kryoCodec) {
        this(kryoCodec.kryoPool.getClasses(), classLoader);
    }

    public KryoCodec(List<Class<?>> classes) {
        this(classes, null);
    }

    public KryoCodec(List<Class<?>> classes, ClassLoader classLoader) {
        this(new KryoPoolImpl(classes, classLoader));
    }

    public KryoCodec(KryoPoolImpl kryoPool) {
        super(kryoPool);
        this.kryoPool = kryoPool;
    }

}

The only change on the latter is the addition of the new constructor which now is required.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mrnikocommented, Mar 6, 2019

@kfh

AttributeMessages serialization now use codec provided in Redisson configuration. Thanks for pointing out!

1reaction
mrnikocommented, Mar 6, 2019

Problem with classloading fixed in https://github.com/redisson/redisson/issues/1959

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's New In Python 3.10 — Python 3.11.1 documentation
Notice this won't work if PyErr_Display() is not called to display the error which can happen if some other custom error display function...
Read more >
Tox Not Respecting Defined envlist in Custom Environments
Use this to specify the python version for a tox environment. If not specified, the virtual environments factors (e.g. name part) will be...
Read more >
Python 3.10.0-a5 - Chocolatey Software
This package depends on the the latest major version of python package. This package do not support package parameters, please install the package...
Read more >
Viz Engine 3.13.0 - Vizrt Documentation Center
Several text bounding box issues were fixed in this Viz Engine release. Starting with version 3.10.0, newlines and/or spaces are ignored ...
Read more >
can't find a codec for class java.time.zoneddatetime - You.com
getOrThrow(CodecCache.java:46) at org.bson.codecs.configuration. ... redisson/redissonCustom codec not working after version 3.10.0#1905.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found