pilgr / Paper

Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.
Apache License 2.0
2.35k stars 234 forks source link

ObjectStreamClass.getConstructorId(Class<?>) is not supported on SDK 27 #123

Closed csshuai closed 6 years ago

csshuai commented 6 years ago

Serialize class:

public class Test implements Serializable {
    private String fileName;

    public Test(String fileName) {
        this.fileName = fileName;
    }
}
java.lang.UnsupportedOperationException: ObjectStreamClass.getConstructorId(Class<?>) is not supported on SDK 27
at java.io.ObjectStreamClass.getConstructorId(ObjectStreamClass.java:2294)
at java.lang.reflect.Method.invoke(Native Method)
at org.objenesis.instantiator.android.Android18Instantiator.findConstructorIdForJavaLangObjectConstructor(Android18Instantiator.java:72)
at org.objenesis.instantiator.android.Android18Instantiator.<init>(Android18Instantiator.java:39)
at org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:96)
at com.esotericsoftware.kryo.Kryo$DefaultInstantiatorStrategy.newInstantiatorOf(Kryo.java:1323)
at com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1127)
at com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1136)
at com.esotericsoftware.kryo.serializers.FieldSerializer.create(FieldSerializer.java:562)
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:71)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:734)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.read(CompatibleFieldSerializer.java:145)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:734)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:543)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:712)
at io.paperdb.KryorStorage.readTableFile(KryorStorage.java:222)
at io.paperdb.KryorStorage.readTableFile(KryorStorage.java:231)
at io.paperdb.KryorStorage.readTableFile(KryorStorage.java:210)
at io.paperdb.KryorStorage.select(KryorStorage.java:133)
at io.paperdb.Kryor.read(Kryor.java:62)
at io.paperdb.Kryor.read(Kryor.java:47)
pilgr commented 6 years ago

Do you serialize class or deserialize? According to stack trace you have exception on read data. If so make sure you read the data you properly saved for the same class Test.

csshuai commented 6 years ago

Sorry for my poor english. I serialize the class Test. Then read it, throw the exception. It is the same class Test.

When i add the default constructor for Test, the read is ok.

Android 8.0 API 26

pilgr commented 6 years ago

Could you show complete code? Or probably test?

On Mar 22, 2018 13:22, "csshuai" notifications@github.com wrote:

Sorry for my poor english. I serialize the class Test. Then read it. It is the same class Test.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/pilgr/Paper/issues/123#issuecomment-375269946, or mute the thread https://github.com/notifications/unsubscribe-auth/AAaNIRSnP_JfD8vaSBaLZyFHuyQh_Cc0ks5tg4mLgaJpZM4S2ax0 .

csshuai commented 6 years ago

I'm sorry, it's my fault.

I added the code to the build.gradle file to cause this error

configurations.all {
    resolutionStrategy.force 'org.objenesis:objenesis:2.2'
}
pilgr commented 6 years ago

no problem