-
Couldn't load subscription status.
- Fork 23
Description
I encountered a fatal crash when trying to save an image with GallerySaver:
E/AndroidRuntime(30094): FATAL EXCEPTION: main
E/AndroidRuntime(30094): Process: , PID: 30094
E/AndroidRuntime(30094): java.lang.NullPointerException
E/AndroidRuntime(30094): at carnegietechnologies.gallery_saver.GallerySaver.finishWithSuccess(GallerySaver.kt:79)
E/AndroidRuntime(30094): at carnegietechnologies.gallery_saver.GallerySaver.access$finishWithSuccess(GallerySaver.kt:16)
E/AndroidRuntime(30094): at carnegietechnologies.gallery_saver.GallerySaver$saveMediaFile$1.invokeSuspend(GallerySaver.kt:74)
E/AndroidRuntime(30094): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime(30094): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
E/AndroidRuntime(30094): at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(30094): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(30094): at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(30094): at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(30094): at android.app.ActivityThread.main(ActivityThread.java:9063)
E/AndroidRuntime(30094): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(30094): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
E/AndroidRuntime(30094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/AndroidRuntime(30094): Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@9d7f9bd, Dispatchers.Main]
I/Process (30094): Sending signal. PID: 30094 SIG: 9
Steps to reproduce:
- Download an image to cache directory (
/data/user/0/<package>/cache/...jpg) - Call
GallerySaver.saveImage(path, albumName: ...) - App crashes with NPE
Notes:
- It seems
finishWithSuccess()is being called with a null result. - This happens more often with cached files, especially on Android 11+ (Scoped Storage).
saveImagereturnsfalsefor some images, and sometimes the app crashes completely.
Expected:
- Should either return
falseor throw a handled exception, not crash the app. - Library should handle null
filePathsafely.
Workaround:
- Migrated to
gallery_saver_pluswhich seems to have fixed this.