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

ManagerConfig causes NotSerializableException #26

Closed
jackcsk opened this issue Aug 12, 2016 · 1 comment
Closed

ManagerConfig causes NotSerializableException #26

jackcsk opened this issue Aug 12, 2016 · 1 comment

Comments

@jackcsk
Copy link

jackcsk commented Aug 12, 2016

In NavigationManagerFragment.onSaveInstanceState(bundle) method, the outState.putSerializable(KEY_MANAGER_CONFIG, mConfig); call throws RuntimeException with the cause of NotSerializableException
Upon investigation, the exception was caused by serialization of INavigationFragment class members, as indicated in the cause:

Caused by java.io.NotSerializableException: com.class.name.RedactedFragment
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
       at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
       at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
       at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
       at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
       at android.os.Parcel.writeSerializable(Parcel.java:1389)
       at android.os.Parcel.writeValue(Parcel.java:1341)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
       at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
       at android.os.Bundle.writeToParcel(Bundle.java:1034)
       at android.os.Parcel.writeBundle(Parcel.java:669)
       at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:144)
       at android.os.Parcel.writeTypedArray(Parcel.java:1197)
       at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:396)
       at android.os.Parcel.writeParcelable(Parcel.java:1363)
       at android.os.Parcel.writeValue(Parcel.java:1268)
       at android.os.Parcel.writeArrayMapInternal(Parcel.java:644)
       at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
       at android.os.Bundle.writeToParcel(Bundle.java:1034)
       at android.os.Parcel.writeBundle(Parcel.java:669)
       at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3091)
       at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3692)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5824)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)

As according to the documentation of ObjectOutputStream.writeObject(obj) method:
http://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html#writeObject(java.lang.Object)

Write the specified object to the ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written. Default serialization for a class can be overridden using the writeObject and the readObject methods. Objects referenced by this object are written transitively so that a complete equivalent graph of objects can be reconstructed by an ObjectInputStream.

My suggestion is to add the keyword transient to the following lines:

    public INavigationFragment rootFragment;

    public INavigationFragment masterFragment;
    public INavigationFragment detailFragment;
@DMCApps
Copy link
Owner

DMCApps commented Aug 16, 2016

Marked the properties transient as per your request. Makes sense considering they are nullified after use anyways so there is no need for them to be serialized. Thanks for the suggestion!

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

2 participants