android-components
android-components copied to clipboard
Prevent RecentlyClosedTabsStorage exceptions
Saw in https://github.com/mozilla-mobile/fenix/issues/25562 that apps may still crash when too much data was persisted in Room and then queried.
E/SQLiteQuery(14924): exception: Row too big to fit into CursorWindow requiredPos=1, totalRows=2; query: SELECT *
E/SQLiteQuery(14924): FROM recently_closed_tabs
E/SQLiteQuery(14924): ORDER BY created_at DESC
E/ExceptionHandler(14924): Uncaught exception handled:
E/ExceptionHandler(14924): android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=1, totalRows=2
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:1001)
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:838)
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:161)
E/ExceptionHandler(14924): at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:131)
E/ExceptionHandler(14924): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:248)
E/ExceptionHandler(14924): at android.database.AbstractCursor.moveToNext(AbstractCursor.java:280)
E/ExceptionHandler(14924): at mozilla.components.feature.recentlyclosed.db.RecentlyClosedTabDao_Impl$4.call(RecentlyClosedTabDao_Impl.java:13)
This exception was intended to be suppressed with a try-catch but a try-catch would only work if we would also collect the stream.
To avoid the exception we should use the declarative way - the catch operator instead of the imperative way - a try-catch block.
┆Issue is synchronized with this Jira Task
Nice find and example code. 🙂
Fixed by https://github.com/mozilla-mobile/android-components/pull/12312.