Skip to content

Commit

Permalink
Upgrade Kryo to 5.0.2
Browse files Browse the repository at this point in the history
=> error: pilgr#4
They said it was fixed in paperdb 2.7.2, but not really!
fix: pilgr#194 (upgrade kryo)

=> why (kryo.setRegistrationRequired(false);)
EsotericSoftware/kryo#398 (comment)
  • Loading branch information
XMKhalid committed Nov 17, 2022
1 parent e3b6f0b commit 0bc8002
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
6 changes: 3 additions & 3 deletions paperdb/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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'
Expand Down
25 changes: 6 additions & 19 deletions paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -387,4 +375,3 @@ private static void sync(FileOutputStream stream) {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 0bc8002

Please sign in to comment.