Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash - Create Dir Paper #66

Closed
thiagohotmart opened this issue Feb 13, 2017 · 12 comments
Closed

Crash - Create Dir Paper #66

thiagohotmart opened this issue Feb 13, 2017 · 12 comments

Comments

@thiagohotmart
Copy link

Hi,

This error started happening frequently in my application, I would like to know if there is anything I can do to prevent it from occurring.

Fatal Exception: java.lang.RuntimeException: Couldn't create Paper dir: /data/data/com.hotmart.sparkle/files/Notification
       at io.paperdb.DbStoragePlainFile.createPaperDir(DbStoragePlainFile.java:288)
       at io.paperdb.DbStoragePlainFile.assertInit(DbStoragePlainFile.java:278)
       at io.paperdb.DbStoragePlainFile.getAllKeys(DbStoragePlainFile.java:160)
       at io.paperdb.Book.getAllKeys(Book.java:96)
       at br.com.hotmart.hifire.util.storage.impl.BaseStorageAbstract.findAll(BaseStorageAbstract.java:78)
       at br.com.hotmart.hifire.util.NotificationUtils.show(NotificationUtils.java:50)
       at br.com.hotmart.hifire.v1.gcm.model.NewPostInTrackPayload.takeAction(NewPostInTrackPayload.java:37)
       at br.com.hotmart.hifire.v1.gcm.model.GcmMessage.takeAction(GcmMessage.java:105)
       at br.com.hotmart.hifire.v1.gcm.GcmListenerServiceImpl.onMessageReceived(GcmListenerServiceImpl.java:62)
       at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
       at com.google.android.gms.gcm.GcmListenerService.zzn(Unknown Source)
       at com.google.android.gms.gcm.GcmListenerService.zzm(Unknown Source)
       at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
       at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)
@pilgr
Copy link
Owner

pilgr commented Feb 13, 2017

Hi,
does crash happen on many devices or just one? Apparently target device experiences some sort of problem with file system. I don't think we can do much about it as Paper just use the common java API to create dir.

@thiagohotmart
Copy link
Author

In many devices, Samsung, Motorola, Azus, Lenovo...

We used Crashlytics to save the crashes and he returned several records for this occurrence.

We use it to save when we receive a GCM notification. And the application is totally in the background.

Can this occur because the context is null?

@pilgr
Copy link
Owner

pilgr commented Feb 13, 2017

Nope, if context is null the crash should happen earlier on getting db path. The exception is thrown at https://github.com/pilgr/Paper/blob/master/paperdb/src/main/java/io/paperdb/DbStoragePlainFile.java#L288 . For Some unknown reasons operation to create necessary dirs was not success. I'll close this issue as I don't see any way for now how to handle this situation better.

@khurram18
Copy link

As per #108 the issue is only in pre 4.4 devices but we are seeing same in Android 6, 7 and 8 as well.

Caused by java.lang.RuntimeException: Couldn't create Paper dir: /data/user/0/com.reme.client/files/io.paperdb
       at io.paperdb.DbStoragePlainFile.createPaperDir(DbStoragePlainFile.java:325)
       at io.paperdb.DbStoragePlainFile.assertInit(DbStoragePlainFile.java:316)
       at io.paperdb.DbStoragePlainFile.insert(DbStoragePlainFile.java:113)
       at io.paperdb.Book.write(Book.java:42)
       at net.intellectsoft.joiful.data.PaperStorage.setForeground(PaperStorage.java:142)
       at net.intellectsoft.joiful.presentation.common.BaseMvpActivity.onPause(BaseMvpActivity.java:77)
       at android.app.Activity.performPause(Activity.java:6557)
       at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1312)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3381)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3354)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3329)
       at android.app.ActivityThread.access$1100(ActivityThread.java:157)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5477)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

@azri92
Copy link

azri92 commented Aug 28, 2019

I'm seeing this issue happen to many different users with different OS versions as well.

@hsyn12
Copy link

hsyn12 commented Feb 8, 2020

this exeption is happening when many threads try to create new directory. it's mean, for the first time use Paper.book("bookName") in different threads cause this exeption. I marked the method with synchronized keyword that use this call and exeption is gone.

@pilgr pilgr reopened this Feb 17, 2020
@DALDEI
Copy link

DALDEI commented Feb 18, 2020

fairly simple:
--> from android studio decompile:

`
private void createPaperDir() {
if (!(new File(this.mDbPath)).exists()) {
boolean isReady = (new File(this.mDbPath)).mkdirs();
if (!isReady) {
throw new RuntimeException("Couldn't create Paper dir: " + this.mDbPath);
}
}

}`

From java rt

public boolean mkdirs() {
    if (exists()) {
        return false;
    }
    if (mkdir()) {
        return true;
    }

Still not obvious?

--- >>>

`

if (exists()) {
return false;
}

`

SO -- if 2 threads call mkdirs() 'at once' very likely one will see the directory already made,
and mkdirs() returns FALSE -- this doesn't mean the directory isnt there -- it means it IS there.
Should not fail.
( try another exists() call -- or as @hsyn12 does slap a synchronized around everything -- but that will only work for the same process)

@pilgr
Copy link
Owner

pilgr commented Feb 18, 2020

Very good point, thanks @DALDEI !

@Sourav242
Copy link

Today I was trying to save the db file in a public directory to access it from multiple apps in my Android Pie, similar error occured with this following code.

Code:
Paper.bookOn("/Download/LocationFiles/").write("trips", newTrips)

Error:
java.lang.RuntimeException: Couldn't create Paper dir: /Download/LocationFiles/io.paperdb at io.paperdb.DbStoragePlainFile.createPaperDir(DbStoragePlainFile.java:325) at io.paperdb.DbStoragePlainFile.assertInit(DbStoragePlainFile.java:316) at io.paperdb.DbStoragePlainFile.insert(DbStoragePlainFile.java:113) at io.paperdb.Book.write(Book.java:42) at com.srvapps.navigationapp.TripHistory$onCreate$5.onClick(TripHistory.kt:66) at android.view.View.performClick(View.java:6614) at android.view.View.performClickInternal(View.java:6591) at android.view.View.access$3100(View.java:786) at android.view.View$PerformClick.run(View.java:25948) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6806) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

What should I do? I tried giving my app WRITE_EXTERNAL_STORAGE permission and also manually created the /Download/LocationFiles/ directory but same error.

@pilgr
Copy link
Owner

pilgr commented Feb 29, 2020

@Sourav242 seems like your issue is related to the #166?

@pilgr
Copy link
Owner

pilgr commented Feb 29, 2020

Please review the PR with the fix #168

@pilgr
Copy link
Owner

pilgr commented May 11, 2020

Fixed and merged to master, included in the new version 2.7.1

@pilgr pilgr closed this as completed May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants