afreakyelf / Pdf-Viewer

A Lightweight PDF Viewer Android library which only occupies around 80kb while most of the Pdf viewer occupies up to 16MB space.
https://afreakyelf.github.io/Pdf-Viewer/
MIT License
820 stars 173 forks source link

[BUG] FileNotFoundException when addBitmapToCache #126

Open bucker opened 7 months ago

bucker commented 7 months ago

📝 Describe the Bug

I found the crash report looks like this:

java.io.FileNotFoundException: /data/user/0/com.myapp.www/cache/___pdf___cache___/0: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
at com.rajat.pdfviewer.util.CacheManager$addBitmapToCache$1.invokeSuspend(CacheManager.java:52)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:8)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:115)
at com.google.android.play.core.tasks.zzc.run(zzc.java)
at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:684)

Suppressed: P9.i: [v0{Cancelling}@59bb3e6, Dispatchers.IO]
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8781)
at libcore.io.IoBridge.open(IoBridge.java:560)

Unable to reproduce it, but seems like it would be possible to access the cache folder /___pdf___cache___ cache has been deleteRecursively().

Since the task to add bitmap to cache will be run on the IO thread, there's no guarantee that the cacheDir will exist when it executes.

The solution might be to check the cacheDir exists before proceeding, but not sure if I have missed anything.

📖 Library Version

github-actions[bot] commented 7 months ago

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon. Need help or want to discuss this issue? Join our Discord community here to ask questions and discuss this issue live!

github-actions[bot] commented 6 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 6 months ago

This issue was closed because it has been stalled for 5 days with no activity.

sunilkumarr1995 commented 3 months ago

@afreakyelf any update on this issue because we are also facing the same thing in production ..!! any help would be grateful.

vivek-np commented 3 months ago

i am facing same issue as well any fixes for this ?

real-Darkshadow commented 2 months ago

@afreakyelf any update on this??

muazdev26 commented 2 weeks ago

Getting the same issue