Skip to content

Crash in main: IllegalStateException: Context is null #6208

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

Closed
nicolas-raoul opened this issue Feb 24, 2025 · 2 comments · Fixed by #6218
Closed

Crash in main: IllegalStateException: Context is null #6208

nicolas-raoul opened this issue Feb 24, 2025 · 2 comments · Fixed by #6218
Assignees
Labels

Comments

@nicolas-raoul
Copy link
Member

Not sure how to reproduce.
I uploaded a pic then browsed my contributions, then went to Explore, I think.

APP_VERSION_NAME=5.1.2-debug-main
ANDROID_VERSION=15
PHONE_MODEL=Pixel 9 Pro
STACK_TRACE=java.lang.IllegalStateException: Context is null
at fr.free.nrw.commons.di.CommonsDaggerSupportFragment.getContext(CommonsDaggerSupportFragment.kt:69)
at fr.free.nrw.commons.media.MediaDetailFragment$onResume$1.onGlobalLayout(MediaDetailFragment.kt:533)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1142)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4214)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3009)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10514)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1566)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1575)
at android.view.Choreographer.doCallbacks(Choreographer.java:1175)
at android.view.Choreographer.doFrame(Choreographer.java:1104)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1549)
at android.os.Handler.handleCallback(Handler.java:991)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
@rohit9625
Copy link
Contributor

I couldn't reproduce this issue. But based on the crash logs this is where the crash occurs while accessing the context.

However, the if condition checks the context for null. But, its getter is throwing the IllegalStateException when the context is null, that's why this check if(context == null) is redundant.

override fun getContext(): Context {
return super.getContext() ?: throw IllegalStateException("Context is null")
}

Previously before migrating MediaDetailFragment to kotlin the code was like below and we didn't have any custom getter for context.

Image

Hence, we should remove the custom getter from the CommonsDaggerSupportFragment file and this crash won't occur again.

What do you think @nicolas-raoul? Please assign me if that works.

@nicolas-raoul
Copy link
Member Author

Sounds reasonable. Thanks!

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

Successfully merging a pull request may close this issue.

3 participants
@nicolas-raoul @rohit9625 and others