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

catch uncaught sqlite exception to prevent crash #321

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteStatement;

Expand Down Expand Up @@ -205,20 +206,16 @@ Optional<Record> selectRecordForKey(String key) {
Cursor cursor = database.query(AppSyncSqlHelper.TABLE_RECORDS,
allColumns, AppSyncSqlHelper.COLUMN_KEY + " = ?", new String[]{key},
null, null, null);
if (cursor == null || !cursor.moveToFirst()) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
return Optional.absent();
}

try {
if (cursor == null || !cursor.moveToFirst()) {
return Optional.absent();
}
Record rec = cursorToRecord(cursor);
return Optional.of(rec);
} catch (IOException exception) {
} catch (IOException | SQLiteException exception) {
return Optional.absent();
} finally {
if (!cursor.isClosed()) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
Expand Down