From 08e43d4622589f44243c9f788a938d9ba884d984 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Mon, 1 May 2023 16:23:58 -0400 Subject: [PATCH] Throw a specific exception for SQLITE_NOTADB. --- .../SQLiteNotADatabaseException.java | 22 +++++++++++++++++++ .../android_database_SQLiteCommon.cpp | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteNotADatabaseException.java diff --git a/sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteNotADatabaseException.java b/sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteNotADatabaseException.java new file mode 100644 index 0000000..82f0456 --- /dev/null +++ b/sqlcipher/src/main/java/net/zetetic/database/sqlcipher/SQLiteNotADatabaseException.java @@ -0,0 +1,22 @@ +package net.zetetic.database.sqlcipher; + +import android.database.sqlite.SQLiteException; + +/** + * An exception that is specific to the "SQLITE_NOTADB" error code. + * + * SQLITE_NOTADB + */ +class SQLiteNotADatabaseException extends SQLiteException { + public SQLiteNotADatabaseException() { + super(); + } + + public SQLiteNotADatabaseException(String error) { + super(error); + } + + public SQLiteNotADatabaseException(String error, Throwable cause) { + super(error, cause); + } +} diff --git a/sqlcipher/src/main/jni/sqlcipher/android_database_SQLiteCommon.cpp b/sqlcipher/src/main/jni/sqlcipher/android_database_SQLiteCommon.cpp index 3751f70..92471c9 100644 --- a/sqlcipher/src/main/jni/sqlcipher/android_database_SQLiteCommon.cpp +++ b/sqlcipher/src/main/jni/sqlcipher/android_database_SQLiteCommon.cpp @@ -74,7 +74,7 @@ void throw_sqlite3_exception(JNIEnv* env, int errcode, /* Upstream treats treat "unsupported file format" error as corruption (SQLiteDatabaseCorruptException). However, SQLITE_NOTADB can occur with mismatched keys, which is not a corruption case, so SQLCipher treats this as a general exception */ - exceptionClass = "android/database/sqlite/SQLiteException"; + exceptionClass = "net/zetetic/database/sqlcipher/SQLiteNotADatabaseException"; break; case SQLITE_CONSTRAINT: exceptionClass = "android/database/sqlite/SQLiteConstraintException";