Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android serialization problems #321

Open
AnnaDKr opened this issue Feb 18, 2022 · 3 comments
Open

Android serialization problems #321

AnnaDKr opened this issue Feb 18, 2022 · 3 comments

Comments

@AnnaDKr
Copy link

AnnaDKr commented Feb 18, 2022

Hi, while using version 2.57 I found that Class object and Timestamp object serialization does not work on Android runtime. Tested on Android 7-12.

Sample class that I want to serialize looks like:

public class SomeClassToSerialize implements Serializable {

    private Class type;

    public SomeClassToSerialize(Class type) {
        this.type = type;
    }
}

And a test case:

SomeClassToSerialize testObject = new SomeClassToSerialize(Object.class);
FSTConfiguration fstConfiguration = FSTConfiguration.createAndroidDefaultConfiguration();
SomeClassToSerialize copy = fstConfiguration.deepCopy(testObject);

It's working when I run it as a test, but in Android app it throws an exception:

2022-02-16 14:47:20.448 13606-13606/eu.eleader.psx.debug E/PsxLog: eleader: Can not make a java.lang.Class constructor accessible
    java.lang.SecurityException: Can not make a java.lang.Class constructor accessible
        at java.lang.reflect.AccessibleObject.setAccessible0(AccessibleObject.java:150)
        at java.lang.reflect.AccessibleObject.setAccessible(AccessibleObject.java:132)
        at org.nustaq.serialization.FSTObjenesisInstantiator.findConstructorForExternalize(FSTObjenesisInstantiator.java:59)
        at org.nustaq.serialization.FSTObjenesisInstantiator.findConstructorForSerializable(FSTObjenesisInstantiator.java:72)
        at org.nustaq.serialization.FSTClazzInfo.<init>(FSTClazzInfo.java:137)
        at org.nustaq.serialization.FSTClazzInfoRegistry.getCLInfo(FSTClazzInfoRegistry.java:129)
        at org.nustaq.serialization.FSTObjectOutput.getFstClazzInfo(FSTObjectOutput.java:534)
        at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:416)
        at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:369)
        at org.nustaq.serialization.FSTObjectOutput.writeObjectFields(FSTObjectOutput.java:664)
        at org.nustaq.serialization.FSTObjectOutput.defaultWriteObject(FSTObjectOutput.java:546)
        at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:458)
        at org.nustaq.serialization.FSTObjectOutput.writeObjectInternal(FSTObjectOutput.java:327)
        at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:294)
        at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:204)
        at org.nustaq.serialization.FSTConfiguration.asByteArray(FSTConfiguration.java:1182)
        at org.nustaq.serialization.FSTConfiguration.deepCopy(FSTConfiguration.java:1036)

Second case:

import java.io.Serializable;
import java.sql.Timestamp;
		
public class SomeClassToSerializeWithTimestamp implements Serializable {

    private Timestamp type;

    public SomeClassToSerializeWithTimestamp(Timestamp type) {
        this.type = type;
    }
}	
SomeClassToSerializeWithTimestamp testObject = new SomeClassToSerializeWithTimestamp(new Timestamp(1645097693462L));
FSTConfiguration fstConfiguration = FSTConfiguration.createAndroidDefaultConfiguration();
SomeClassToSerializeWithTimestamp copy = fstConfiguration.deepCopy(testObject);

This time app threw exception:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
     at org.nustaq.serialization.FSTClazzInfo$FSTFieldInfo.getObjectValue(FSTClazzInfo.java:873)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectFields(FSTObjectOutput.java:660)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectCompatibleRecursive(FSTObjectOutput.java:576)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectCompatible(FSTObjectOutput.java:554)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:450)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:369)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectFields(FSTObjectOutput.java:664)
     at org.nustaq.serialization.FSTObjectOutput.defaultWriteObject(FSTObjectOutput.java:546)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:458)
     at org.nustaq.serialization.FSTObjectOutput.writeObjectInternal(FSTObjectOutput.java:327)
     at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:294)
     at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:204)
     at org.nustaq.serialization.FSTConfiguration.asByteArray(FSTConfiguration.java:1182)
     at org.nustaq.serialization.FSTConfiguration.deepCopy(FSTConfiguration.java:1036)	
@bigsinger
Copy link

me too

@bigsinger
Copy link

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
at org.nustaq.serialization.FSTClazzInfo$FSTFieldInfo.getObjectValue(FSTClazzInfo.java:873)
at org.nustaq.serialization.FSTObjectOutput.writeObjectFields(FSTObjectOutput.java:660)
at org.nustaq.serialization.FSTObjectOutput$3.defaultWriteObject(FSTObjectOutput.java:916)
at java.io.File.writeObject(File.java:2138)
at java.lang.reflect.Method.invoke(Native Method)
at org.nustaq.serialization.FSTObjectOutput.writeObjectCompatibleRecursive(FSTObjectOutput.java:566)
at org.nustaq.serialization.FSTObjectOutput.writeObjectCompatible(FSTObjectOutput.java:554)
at org.nustaq.serialization.FSTObjectOutput.writeObjectWithContext(FSTObjectOutput.java:450)
at org.nustaq.serialization.FSTObjectOutput.writeObjectInternal(FSTObjectOutput.java:327)
at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:294)
at org.nustaq.serialization.FSTObjectOutput.writeObject(FSTObjectOutput.java:204)
at org.nustaq.serialization.FSTConfiguration.asByteArray(FSTConfiguration.java:1182)
at com.xsl.app.MainActivity.onCreate(MainActivity.java:48)
at android.app.Activity.performCreate(Activity.java:8488)
at android.app.Activity.performCreate(Activity.java:8461)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1343)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4602)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4842)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:113)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2928)
at android.os.Handler.dispatchMessage(Handler.java:117)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:293)
at android.app.ActivityThread.main(ActivityThread.java:9596)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1204)

@simonpoole
Copy link

I suspect the later issue is the same as what I mention here #288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants