rafi0101 / Android-Room-Database-Backup

Simple tool to backup and restore your room database in Android
MIT License
241 stars 19 forks source link

Crash when database restoring with wrong password #13

Closed T2skler closed 2 years ago

T2skler commented 2 years ago

Hi. First, I want say to you great thanks for this project ;-) I found one bug. In my application I have possibility change password for other backups. When I use backupLocation(RoomBackup.BACKUP_FILE_LOCATION_CUSTOM_DIALOG) and try restore with wrong password - application will be crashed and all room data will erased. Can you add possibility control check password before restoring?

            roomBackup.onCompleteListener((success, message) -> {
                Log.i("DB_RESTORE", "success: " + success + ", message: " + message);
                if (success) {
                    ToastUtils.show(requireContext(), R.string.database_was_restored);
                    roomBackup.restartApp(new Intent(requireContext(), AuthenticationActivity.class));
                } else {
                    ToastUtils.show(requireContext(), R.string.msg_error_restore_backup);
                }
            });
            roomBackup.restore();
java.lang.NullPointerException: Attempt to get length of null array
    at java.io.FilterOutputStream.write(FilterOutputStream.java:103)
    at de.raphaelebner.roomdatabasebackup.core.RoomBackup.doRestore(RoomBackup.kt:576)
    at de.raphaelebner.roomdatabasebackup.core.RoomBackup.openBackupfileChooser$lambda-8(RoomBackup.kt:668)
    at de.raphaelebner.roomdatabasebackup.core.RoomBackup.$r8$lambda$9hK7PGk7yQJfRSepVJ8YQaL-7oE(Unknown Source:0)
    at de.raphaelebner.roomdatabasebackup.core.RoomBackup$$ExternalSyntheticLambda3.onActivityResult(Unknown Source:4)
    at androidx.activity.result.ActivityResultRegistry$1.onStateChanged(ActivityResultRegistry.java:148)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
    at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
    at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
    at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
    at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
    at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
    at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187)
    at android.app.Activity.dispatchActivityPostStarted(Activity.java:1429)
    at android.app.Activity.performStart(Activity.java:8229)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3565)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2135)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8056)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
rafi0101 commented 2 years ago

Hi @T2skler, thank you for your feedback! I will have a look in the next few days

rafi0101 commented 2 years ago

This problem should be fixed now with this release: v1.0.0-beta10

T2skler commented 2 years ago

Эта проблема должна быть исправлена ​​в этом выпуске: v1.0.0-beta10

Thanx man. Your code works is perfect!