mastodon / mastodon-android

Official Android app for Mastodon
https://app.joinmastodon.org/android
GNU General Public License v3.0
1.71k stars 263 forks source link

App crashes when viewing TL #880

Closed edgarogh closed 2 months ago

edgarogh commented 2 months ago

The app crashes immediately when started. It just started happening so I suppose it's caused by a malformed toot JSON. Whether or not the server (instance) is in the wrong or not, it shouldn't be possible for a server to remotely crash a client app.

--------- beginning of crash
14531 E AndroidRuntime: FATAL EXCEPTION: databaseThread
14531 E AndroidRuntime: Process: org.joinmastodon.android, PID: 14251
14531 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'long j$.time.Instant.getEpochSecond()' on a null object reference
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController.lambda$putHomeTimeline$3(SourceFile:120)
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController.$r8$lambda$AJyW915yvcdDM3uSOc-JvH42ce8(SourceFile:0)
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController$$ExternalSyntheticLambda6.run(SourceFile:0)
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController.lambda$runOnDbThread$16(SourceFile:340)
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController.$r8$lambda$MQ0qlJB6DpKl0fkTnizgW1HSB6c(SourceFile:0)
14531 E AndroidRuntime:     at org.joinmastodon.android.api.CacheController$$ExternalSyntheticLambda10.run(SourceFile:0)
14531 E AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:959)
14531 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:100)
14531 E AndroidRuntime:     at android.os.Looper.loopOnce(Looper.java:232)
14531 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:317)
14531 E AndroidRuntime:     at me.grishka.appkit.utils.WorkerThread.run(SourceFile:54)

Relevant code: https://github.com/mastodon/mastodon-android/blob/2c9e92a254907772757cdc932fd37667fc9218bb/mastodon/src/main/java/org/joinmastodon/android/api/CacheController.java#L132

grishka commented 2 months ago

That's interesting. It should not be possible for this field to be null because it has an annotation that it's required: https://github.com/mastodon/mastodon-android/blob/2c9e92a254907772757cdc932fd37667fc9218bb/mastodon/src/main/java/org/joinmastodon/android/model/Status.java#L24-L25 The validation happens after the response is parsed and before any further processing, and if any field with this annotation in any part of the response is null, it's treated like a network error, so it's really odd that this malformed object somehow gets this far. So it clearly must be a bug in the compiler, the Android runtime, the Linux kernel, the CPU in your phone, or the laws of physics, no way it is a bug in my code, it can't possibly be.

I need more details to try to reproduce this. What server are you using?

edgarogh commented 2 months ago

The problem was between my chair bed and my phone's screen, surprisingly. I had this issue on a fork of the app which removed the annotation for some reason. Before reporting it on their repository, I tried to test it on the upstream app (this one) to see if it also happened here, and I must've completely messed up my test because I was sure I managed to get the Mastodon app to crash. I just double checked and indeed, fortunately, none of the compiler, ART, CPU or laws or physics are broken. Mastodon doesn't crash, and properly displays an error message. This still means that my timeline is effectively broken on all major apps as of right now, but since I'm using a pleroma instance, their broken API/validation is none of your responsibility. Sorry for the inconvenience, and have a good week-end!