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

Crash when reading old cache #22

Closed
mvnowak opened this issue Aug 3, 2022 · 6 comments
Closed

Crash when reading old cache #22

mvnowak opened this issue Aug 3, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@mvnowak
Copy link
Contributor

mvnowak commented Aug 3, 2022

Unfortunately this bug seems to keep reappearing😄 The clean install of 5.1.4 works perfectly fine (also thanks for crediting me in the release notes) but when updating from 4.0.1 with an existing save file it crashes again.

However this time its reproducible in the Emulator, so maybe that helps in getting rid of the bug.

Steps to reproduce:

  1. Check out the revision of the repository where version was updated to 4.0.1
  2. Build and clean install this version on the emulator
  3. Open the app and create an entry
  4. Check out the current master branch (5.1.4) and update the app on the emulator by building and running again

I appended the full crash log at the end, but the only relevant lines are

Caused by: java.io.InvalidClassException: com.katiearose.sobriety.Addiction;
at com.katiearose.sobriety.CacheHandler.readCache(CacheHandler.kt:17)
at com.katiearose.sobriety.Main.onCreate(Main.kt:61)

I don't really get why it crashes, because there is try catch blocks everywhere that should have caught that exception.
Mabye its worth considering to use a different way of storage, since these FileOutPutStreams etc. are a bit tricky to debug. Since the data is very simple, you could use Android's Shared Preferences, and save the list as a serialized string in a single key value pair there. Or if you want to debug the current system, here is the full crash log:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.katiearose.sobriety, PID: 21703
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.katiearose.sobriety/com.katiearose.sobriety.Main}: java.io.InvalidClassException: com.katiearose.sobriety.Addiction; local class incompatible: stream classdesc serialVersionUID = -8477717136644775154, local class serialVersionUID = 7971970991809636397
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.io.InvalidClassException: com.katiearose.sobriety.Addiction; local class incompatible: stream classdesc serialVersionUID = -8477717136644775154, local class serialVersionUID = 7971970991809636397
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:624)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1713)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1594)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1872)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1412)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427)
at java.util.ArrayList.readObject(ArrayList.java:791)
at java.lang.reflect.Method.invoke(Native Method)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1066)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2013)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1899)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1412)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427)
at com.katiearose.sobriety.CacheHandler.readCache(CacheHandler.kt:17)
at com.katiearose.sobriety.Main.onCreate(Main.kt:61)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7839) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

@KiARC
Copy link
Owner

KiARC commented Aug 3, 2022

Oh this one is my bad actually because Addiction was modified in the new version and I need to update the readLegacyCache function to use the AddictionOld class instead iirc. Maybe I already did and am just tired since it's the morning but I'm fairly sure that's what's wrong.

@KiARC KiARC added the bug Something isn't working label Aug 3, 2022
@KiARC
Copy link
Owner

KiARC commented Aug 3, 2022

Wait... No that isn't it, that class was scrapped

@KiARC
Copy link
Owner

KiARC commented Aug 3, 2022

Ahhhh that is it, and I made a mistake scrapping it. Essentially, the 5.1.4 Addiction class isn't the same as the 4.0.1 Addiction class, so I need a legacy one in there to facilitate cache reads. On top of that, readLegacyCache() is still set up to read 3.x.x caches 🤦‍♀️

@KiARC
Copy link
Owner

KiARC commented Aug 3, 2022

So yeah I'll fix that later today

@KiARC
Copy link
Owner

KiARC commented Aug 4, 2022

Ah. Bigger issue. Because of how JVM serialization works, you can't rename a class and still deserialize things properly, so I need to see what I can do, but it may be that 4.x.x caches will not work with 5.x.x and I'll need to start designing a more long-term-stable cache format.

@KiARC
Copy link
Owner

KiARC commented Aug 4, 2022

Technically solved, and the new cache format is WIP now.

@KiARC KiARC closed this as completed Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants