hi-manshu / Pluck

Pluck, a library that helps you to pick image via Gallery/Camera built using Compose
https://www.himanshoe.com
Apache License 2.0
374 stars 24 forks source link

java.lang.NullPointerException' on folderName.toString() #11

Open jokot opened 2 years ago

jokot commented 2 years ago

Describe the bug NullPointerException -> force close when folderName is null, its happen when image is on the root folder, just like this log

Library version 1.0.0-RC1

Log from library

D/imagesPlu: id : 17264, contentUri: content://media/external/images/media/17264, diplayName: Screenshot_20220315-151458.png, folder: Screenshots
D/imagesPlu: id : 17263, contentUri: content://media/external/images/media/17263, diplayName: Screenshot_20220315-151314.png, folder: Screenshots
D/imagesPlu: id : 17262, contentUri: content://media/external/images/media/17262, diplayName: ktp2.jpg, folder: null

Error log

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.imagepickerapp, PID: 3931
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toString()' on a null object reference
        at com.himanshoe.pluck.util.MediaLoaderKt.fetchPagePicture(MediaLoader.kt:97)
        at com.himanshoe.pluck.data.PluckRepositoryImpl$getPicturePagingSource$1.invoke(PluckRepository.kt:50)
        at com.himanshoe.pluck.data.PluckRepositoryImpl$getPicturePagingSource$1.invoke(PluckRepository.kt:50)
        at com.himanshoe.pluck.data.PluckDataSource.load(PluckDataSource.kt:40)
        at androidx.paging.PageFetcherSnapshot.doInitialLoad(PageFetcherSnapshot.kt:283)
        at androidx.paging.PageFetcherSnapshot.access$doInitialLoad(PageFetcherSnapshot.kt:54)
        at androidx.paging.PageFetcherSnapshot$pageEventFlow$1.invokeSuspend(PageFetcherSnapshot.kt:163)
        at androidx.paging.PageFetcherSnapshot$pageEventFlow$1.invoke(Unknown Source:8)
        at androidx.paging.PageFetcherSnapshot$pageEventFlow$1.invoke(Unknown Source:4)
        at androidx.paging.CancelableChannelFlowKt$cancelableChannelFlow$1.invokeSuspend(CancelableChannelFlow.kt:30)
        at androidx.paging.CancelableChannelFlowKt$cancelableChannelFlow$1.invoke(Unknown Source:8)
        at androidx.paging.CancelableChannelFlowKt$cancelableChannelFlow$1.invoke(Unknown Source:4)
        at androidx.paging.SimpleChannelFlowKt$simpleChannelFlow$1$1$producer$1$1.invokeSuspend(SimpleChannelFlow.kt:57)
        at androidx.paging.SimpleChannelFlowKt$simpleChannelFlow$1$1$producer$1$1.invoke(Unknown Source:8)
        at androidx.paging.SimpleChannelFlowKt$simpleChannelFlow$1$1$producer$1$1.invoke(Unknown Source:4)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
        at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
        at androidx.paging.SimpleChannelFlowKt$simpleChannelFlow$1$1$producer$1.invokeSuspend(SimpleChannelFlow.kt:52)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
        at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:375)
        at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith$default(DispatchedContinuation.kt:278)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:39)
        at kotlinx.coroutines.LazyStandaloneCoroutine.onStart(Builders.common.kt:204)
        at kotlinx.coroutines.JobSupport.startInternal(JobSupport.kt:401)
        at kotlinx.coroutines.JobSupport.start(JobSupport.kt:380)
        at androidx.paging.CachedPageEventFlow$sharedForDownstream$1.invokeSuspend(CachedPageEventFlow.kt:66)
        at androidx.paging.CachedPageEventFlow$sharedForDownstream$1.invoke(Unknown Source:8)
        at androidx.paging.CachedPageEventFlow$sharedForDownstream$1.invoke(Unknown Source:4)
        at kotlinx.coroutines.flow.SubscribedFlowCollector.onSubscription(Share.kt:410)
        at kotlinx.coroutines.flow.SharedFlowImpl.collect(SharedFlow.kt:341)
        at kotlinx.coroutines.flow.SubscribedSharedFlow.collect(Share.kt:400)
        at kotlinx.coroutines.flow.FlowKt__LimitKt$takeWhile$$inlined$unsafeFlow$1.collect(SafeCollector.common.kt:124)
        at androidx.paging.CachedPageEventFlow$downstreamFlow$1.invokeSuspend(CachedPageEventFlow.kt:247)
        at androidx.paging.CachedPageEventFlow$downstreamFlow$1.invoke(Unknown Source:8)
        at androidx.paging.CachedPageEventFlow$downstreamFlow$1.invoke(Unknown Source:4)
        at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
        at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:212)
        at androidx.paging.PagingDataDiffer$collectFrom$2.invokeSuspend(PagingDataDiffer.kt:467)
        at androidx.paging.PagingDataDiffer$collectFrom$2.invoke(Unknown Source:8)
        at androidx.paging.PagingDataDiffer$collectFrom$2.invoke(Unknown Source:2)
        at androidx.paging.SingleRunner$runInIsolation$2.invokeSuspend(SingleRunner.kt:59)
E/AndroidRuntime:     at androidx.paging.SingleRunner$runInIsolation$2.invoke(Unknown Source:8)
        at androidx.paging.SingleRunner$runInIsolation$2.invoke(Unknown Source:4)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
        at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
        at androidx.paging.SingleRunner.runInIsolation(SingleRunner.kt:49)
        at androidx.paging.SingleRunner.runInIsolation$default(SingleRunner.kt:44)
        at androidx.paging.PagingDataDiffer.collectFrom(PagingDataDiffer.kt:140)
        at androidx.paging.compose.LazyPagingItems$collectPagingData$2.invokeSuspend(LazyPagingItems.kt:192)
        at androidx.paging.compose.LazyPagingItems$collectPagingData$2.invoke(Unknown Source:8)
        at androidx.paging.compose.LazyPagingItems$collectPagingData$2.invoke(Unknown Source:4)
        at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invokeSuspend(Merge.kt:217)
        at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invoke(Unknown Source:13)
        at kotlinx.coroutines.flow.FlowKt__MergeKt$mapLatest$1.invoke(Unknown Source:4)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invokeSuspend(Merge.kt:34)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Unknown Source:8)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Unknown Source:4)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$$inlined$collect$1.emit(Collect.kt:140)
        at kotlinx.coroutines.flow.SharedFlowImpl.collect(SharedFlow.kt:351)
        at kotlinx.coroutines.flow.ReadonlySharedFlow.collect(Unknown Source:2)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invokeSuspend(Merge.kt:101)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Unknown Source:8)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Unknown Source:4)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
        at kotlinx.coroutines.flow.internal.FlowCoroutineKt.flowScope(FlowCoroutine.kt:33)
        at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest.flowCollect(Merge.kt:25)
        at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:157)
        at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(Unknown Source:0)
        at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
        at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
        at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7397)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)

To Reproduce Steps to reproduce the behavior:

  1. On your phone, save any picture that you have to root folder of your storage
  2. Implement pluck with permission
    Permission(
    permissions = listOf(
        Manifest.permission.CAMERA,
        Manifest.permission.READ_EXTERNAL_STORAGE
    ),
    goToAppSettings = {
        // Go to App Settings
    }
    ) {
    Pluck(onPhotoSelected = {
        // List of PluckImage when selecting from Gallery/Camera. When checking with Camera
        // It returns only one item in list
    })
    }
  3. run the app on debug mode
  4. accept permission
  5. See error

Desktop

Android Studio

Smartphone (please complete the following information):

hi-manshu commented 2 years ago

Thank you for this, will check this on priority !

m1r0n41k commented 2 years ago

Any updates of this?

hi-manshu commented 2 years ago

Hey can you check now with the new release