Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Fix NullPointerException when receiving push when killed #914

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

p1gp1g
Copy link

@p1gp1g p1gp1g commented Nov 1, 2023

When receiving a push notification while the app is killed, filterStatusContainingObjects is called and it uses localPreferences before it is initialized and causes a NullPointerException. This PR changes AccountSession.class so getLocalPreferences is always called to be sure localPreferences is initialized.


logcat:

2023-10-30 19:38:56.860 16727-16727 AndroidRuntime          pid-16727                            E  FATAL EXCEPTION: main
                                                                                                    Process: org.joinmastodon.android.sk.debug, PID: 16727
                                                                                                    java.lang.NullPointerException: Attempt to read from field 'boolean org.joinmastodon.android.api.session.AccountLocalPreferences.serverSideFiltersSupported' on a null object reference in method 'void org.joinmastodon.android.api.session.AccountSession.filterStatusContainingObjects(java.util.List, java.util.function.Function, org.joinmastodon.android.model.FilterContext, org.joinmastodon.android.model.Account)'
                                                                                                    	at org.joinmastodon.android.api.session.AccountSession.filterStatusContainingObjects(AccountSession.java:268)
                                                                                                    	at org.joinmastodon.android.api.session.AccountSession.filterStatusContainingObjects(AccountSession.java:254)
                                                                                                    	at org.joinmastodon.android.api.CacheController$2.onSuccess(CacheController.java:192)
                                                                                                    	at org.joinmastodon.android.api.CacheController$2.onSuccess(CacheController.java:188)
                                                                                                    	at me.grishka.appkit.api.APIRequest$1.run(APIRequest.java:29)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8199)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

@p1gp1g
Copy link
Author

p1gp1g commented Nov 1, 2023

Fix #909

@d4f5409d
Copy link

d4f5409d commented Nov 1, 2023

Maybe this also fixes the crash when sharing stuff from context menu.

@p1gp1g
Copy link
Author

p1gp1g commented Nov 1, 2023

Maybe this also fixes the crash when sharing stuff from context menu.

This is a different issue, but I can give a look

@sk22 sk22 merged commit 2818672 into sk22:main Nov 10, 2023
1 check passed
@d4f5409d
Copy link

It fixed the push notification error, but context menu crash still not fixed ://

FATAL EXCEPTION: main
Process: org.joinmastodon.android.sk, PID: 23743
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.joinmastodon.android.sk/org.joinmastodon.android.ExternalShareActivity}: java.lang.NullPointerException: Attempt to read from field 'java.util.List org.joinmastodon.android.model.Instance.languages' on a null object reference in method 'void org.joinmastodon.android.utils.MastodonLanguage$LanguageResolver.<init>(org.joinmastodon.android.model.Instance)'
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3876)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4018)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:111)
	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:2474)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:240)
	at android.os.Looper.loop(Looper.java:351)
	at android.app.ActivityThread.main(ActivityThread.java:8427)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.util.List org.joinmastodon.android.model.Instance.languages' on a null object reference in method 'void org.joinmastodon.android.utils.MastodonLanguage$LanguageResolver.<init>(org.joinmastodon.android.model.Instance)'
	at org.joinmastodon.android.utils.MastodonLanguage$LanguageResolver.<init>(SourceFile:98)
	at org.joinmastodon.android.fragments.ComposeFragment.onCreate(SourceFile:234)
	at android.app.Fragment.performCreate(Fragment.java:2486)
	at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1261)
	at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
	at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
	at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
	at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
	at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:822)
	at me.grishka.appkit.FragmentStackActivity.showFragment(SourceFile:108)
	at me.grishka.appkit.FragmentStackActivity.showFragmentClearingBackStack(SourceFile:196)
	at org.joinmastodon.android.ExternalShareActivity.openComposeFragment(SourceFile:132)
	at org.joinmastodon.android.ExternalShareActivity.onCreate(SourceFile:79)
	at android.app.Activity.performCreate(Activity.java:8422)
	at android.app.Activity.performCreate(Activity.java:8395)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1403)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3849)
	... 12 more

@d4f5409d
Copy link

I don't know what's going on. I do not get notifications again

@sk22
Copy link
Owner

sk22 commented Nov 17, 2023

I don't know what's going on. I do not get notifications again

if you updated using f-droid or downloaded the f-droid variant, this removed the FCM (firebase cloud messaging) compatibility, so that might be why. you could use the github variant (megalodon.apk) or the one from google play instead

@d4f5409d
Copy link

Okay, heads up: I do get notifications, but not everytime. I was able to catch a crash via LogFox:

Process: org.joinmastodon.android.sk, PID: 942
java.lang.NullPointerException: Attempt to read from field 'org.joinmastodon.android.model.Account org.joinmastodon.android.model.Status.account' on a null object reference in method 'org.joinmastodon.android.model.PushNotification org.joinmastodon.android.model.PushNotification.fromNotification(android.content.Context, org.joinmastodon.android.model.Notification)'
	at org.joinmastodon.android.model.PushNotification.fromNotification(SourceFile:55)
	at org.joinmastodon.android.PushNotificationReceiver.notifyUnifiedPush(SourceFile:153)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1.lambda$onSuccess$0(SourceFile:75)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1.$r8$lambda$4J7AuBytjmt8335OwYDlx1gnhvU(SourceFile:0)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1$$ExternalSyntheticLambda0.run(SourceFile:0)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:240)
	at android.os.Looper.loop(Looper.java:351)
	at me.grishka.appkit.utils.WorkerThread.run(SourceFile:54)

@d4f5409d
Copy link

Another one: crash when notifications incoming:

2023-11-20T15:48:58.094Z

java.lang.IllegalStateException: Unexpected value: STATUS
	at org.joinmastodon.android.model.PushNotification.fromNotification(SourceFile:51)
	at org.joinmastodon.android.PushNotificationReceiver.notifyUnifiedPush(SourceFile:153)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1.lambda$onSuccess$0(SourceFile:75)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1.$r8$lambda$4J7AuBytjmt8335OwYDlx1gnhvU(SourceFile:0)
	at org.joinmastodon.android.UnifiedPushNotificationReceiver$1$$ExternalSyntheticLambda0.run(SourceFile:0)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:240)
	at android.os.Looper.loop(Looper.java:351)
	at me.grishka.appkit.utils.WorkerThread.run(SourceFile:54)

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

Successfully merging this pull request may close these issues.

3 participants