From 0bc8002aa9ccd095792618f567a17b18cc7cf09d Mon Sep 17 00:00:00 2001 From: khalid asnaa <kasnaa@opentext.com> Date: Thu, 17 Nov 2022 09:15:01 -0500 Subject: [PATCH] Upgrade Kryo to 5.0.2 => error: https://github.com/pilgr/Paper/issues/4 They said it was fixed in paperdb 2.7.2, but not really! fix: https://github.com/pilgr/Paper/pull/194 (upgrade kryo) => why (kryo.setRegistrationRequired(false);) https://github.com/EsotericSoftware/kryo/issues/398#issuecomment-276674602 --- paperdb/build.gradle | 6 ++--- .../java/io/paperdb/DbStoragePlainFile.java | 25 +++++-------------- .../serializer/NoArgCollectionSerializer.java | 2 +- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/paperdb/build.gradle b/paperdb/build.gradle index 3fb50a4..49a6bb4 100644 --- a/paperdb/build.gradle +++ b/paperdb/build.gradle @@ -15,7 +15,7 @@ repositories { } ext { - PUBLISH_GROUP_ID = 'io.github.pilgr' + PUBLISH_GROUP_ID = 'io.paperdb' PUBLISH_VERSION = '2.7.2' PUBLISH_ARTIFACT_ID = 'paperdb' } @@ -68,8 +68,8 @@ afterEvaluate { } dependencies { - api 'com.esotericsoftware:kryo:4.0.1' - api 'de.javakaffee:kryo-serializers:0.40' + api 'com.esotericsoftware:kryo:5.2.0' + api 'de.javakaffee:kryo-serializers:0.45' implementation "androidx.appcompat:appcompat:1.3.1" androidTestImplementation 'androidx.test:rules:1.2.0' diff --git a/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java b/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java index 8fba07b..8a1b182 100644 --- a/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java +++ b/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java @@ -9,6 +9,7 @@ import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer; +import com.esotericsoftware.kryo.util.DefaultInstantiatorStrategy; import org.objenesis.strategy.StdInstantiatorStrategy; @@ -48,17 +49,13 @@ private Kryo getKryo() { private final ThreadLocal<Kryo> mKryo = new ThreadLocal<Kryo>() { @Override protected Kryo initialValue() { - return createKryoInstance(false); + return createKryoInstance(); } }; - private Kryo createKryoInstance(boolean compatibilityMode) { + private Kryo createKryoInstance() { Kryo kryo = new Kryo(); - - if (compatibilityMode) { - kryo.getFieldSerializerConfig().setOptimizedGenerics(true); - } - + kryo.setRegistrationRequired(false); kryo.register(PaperTable.class); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); kryo.setReferences(false); @@ -83,7 +80,7 @@ private Kryo createKryoInstance(boolean compatibilityMode) { kryo.register(clazz, mCustomSerializers.get(clazz)); kryo.setInstantiatorStrategy( - new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); + new DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); return kryo; } @@ -309,18 +306,9 @@ private <E> E readTableFile(String key, File originalFile) { try { return readContent(originalFile, getKryo()); } catch (FileNotFoundException | KryoException | ClassCastException e) { - Throwable exception = e; - // Give one more chance, read data in paper 1.x compatibility mode - if (e instanceof KryoException) { - try { - return readContent(originalFile, createKryoInstance(true)); - } catch (FileNotFoundException | KryoException | ClassCastException compatibleReadException) { - exception = compatibleReadException; - } - } String errorMessage = "Couldn't read/deserialize file " + originalFile + " for table " + key; - throw new PaperDbException(errorMessage, exception); + throw new PaperDbException(errorMessage, e); } } @@ -387,4 +375,3 @@ private static void sync(FileOutputStream stream) { } } } - diff --git a/paperdb/src/main/java/io/paperdb/serializer/NoArgCollectionSerializer.java b/paperdb/src/main/java/io/paperdb/serializer/NoArgCollectionSerializer.java index 7ae3dd0..fa438d3 100644 --- a/paperdb/src/main/java/io/paperdb/serializer/NoArgCollectionSerializer.java +++ b/paperdb/src/main/java/io/paperdb/serializer/NoArgCollectionSerializer.java @@ -15,7 +15,7 @@ */ public class NoArgCollectionSerializer extends CollectionSerializer { @Override - protected Collection create(Kryo kryo, Input input, Class<Collection> type) { + protected Collection create(Kryo kryo, Input input, Class type, int size) { return new ArrayList(); } }