Custom codec not working after version 3.10.0
See original GitHub issueWe 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:
- Created 5 years ago
- Comments:11 (4 by maintainers)
@kfh
AttributeMessages serialization now use codec provided in Redisson configuration. Thanks for pointing out!
Problem with classloading fixed in https://github.com/redisson/redisson/issues/1959