Skip to content

NullPointerException in GallerySaver.finishWithSuccess when saving image #18

@NGUYENDINHATK2

Description

@NGUYENDINHATK2

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:

  1. Download an image to cache directory (/data/user/0/<package>/cache/...jpg)
  2. Call GallerySaver.saveImage(path, albumName: ...)
  3. 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).
  • saveImage returns false for some images, and sometimes the app crashes completely.

Expected:

  • Should either return false or throw a handled exception, not crash the app.
  • Library should handle null filePath safely.

Workaround:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions