onseok/peekaboo

Crash on Android

Opened this issue · 0 comments

Got a crash report in Sentry from an Andorid app.

Stacktrace:

java.lang.NullPointerException: null
    at com.preat.peekaboo.image.picker.PeekabooImageResizer.getOriginalImageByteArray
    at com.preat.peekaboo.image.picker.PeekabooImageResizer.getOriginalImageByteArray
    at com.preat.peekaboo.image.picker.PeekabooImageResizer.access$getOriginalImageByteArray
    at com.preat.peekaboo.image.picker.PeekabooImageResizer$resizeImageAsync$1$2.invokeSuspend
    at com.preat.peekaboo.image.picker.PeekabooImageResizer$resizeImageAsync$1$2.invokeSuspend
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith
    at kotlinx.coroutines.DispatchedTask.run
    at kotlinx.coroutines.DispatchedTask.run
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8061)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

The offending code is:

return context.contentResolver.openInputStream(uri)?.use { inputStream ->
    val bitmap = BitmapFactory.decodeStream(inputStream)
    val rotatedBitmap = rotateImageIfRequired(context, bitmap, uri)

    ByteArrayOutputStream().apply {
        rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, this)
    }.toByteArray()
}

The documentation for BitmapFactory.decodeStream mentions, that it can return null. So thats most likely where the NullPointer originates from. Maybe the user picked an invalid image somehow.