0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

fix: Don't crash if no WebView

After a bad init, we tested to see the database version

If there was no WebView, AnkiDroidApp hadn't performed an init

This caused a path where `new Db(path)` could be called when the
database wasn't created, using a Java style database init without
handling creating the `col` table

We then crashed as there was no default deck

Related: 9226
This commit is contained in:
David Allison 2021-07-08 19:16:44 +01:00 committed by Mike Hardy
parent c60d5d4ccc
commit 876180e614

View File

@ -32,6 +32,7 @@ import com.ichi2.utils.JSONException;
import com.ichi2.utils.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
@ -57,6 +58,9 @@ public class Storage {
/** Helper method for when the collection can't be opened */
public static int getDatabaseVersion(String path) throws UnknownDatabaseVersionException {
try {
if (!new File(path).exists()) {
throw new UnknownDatabaseVersionException(new FileNotFoundException(path));
}
DB db = new DB(path);
int result = db.queryScalar("SELECT ver FROM col");
db.close();