Library version used: 4.19.1
Room version used: 2.8.5 & 3.0.3
I'm currently upgrading to room3 and during the Prepare and modernize in Room 2.x part of the Android documentation I'm running into an runtime error.
At the stage Set the SQLite driver I'm doing it like your documentation says and pass a SQLCipherDriver to the databaseBuilder.
Using the @Upsert annotation (both in room2 and room3) now leads to an UNIQUE constraint failed exception at runtime. This also happens after a complete upgrade to room3.
This does not happen when using the room2 way with SupportOpenHelperFactory.
This is what Claude analyzed:
Room implements @upsert as:
- try a plain INSERT (conflict strategy ABORT),
- catch the constraint exception, check it's a uniqueness violation,
- fall back to UPDATE.
Step 2 is the fragile part: it is a catch on a specific exception type plus a string match on the message. Room's driver-based adapter catches androidx.sqlite.SQLiteException.
SupportOpenHelperFactory went through Room's SupportSQLiteDriver wrapper, where the error surfaced in a form Room's fallback recognised, so step 3 ran and you never saw the error. SQLCipherDriver hands Room SQLCipher's own
net.zetetic.database.sqlcipher.SQLiteConstraintException instead (the (code 1555); query: … message format is zetetic's native formatter). That type is not androidx.sqlite.SQLiteException, so the catch never fires, the UPDATE
fallback is skipped, and the raw insert failure propagates to you.
This is the same class of bug as sqlcipher-android#23 (#23) (@upsert + SQLCipher) and robolectric#8469 (robolectric/robolectric#8469) — any driver
that wraps SQLite errors in its own exception hierarchy breaks Room's upsert fallback. sqlcipher-android#84 (#84) tracks the broader Room 3 / SQLiteDriver migration gap.
Library version used: 4.19.1
Room version used: 2.8.5 & 3.0.3
I'm currently upgrading to room3 and during the Prepare and modernize in Room 2.x part of the Android documentation I'm running into an runtime error.
At the stage Set the SQLite driver I'm doing it like your documentation says and pass a
SQLCipherDriverto thedatabaseBuilder.Using the @Upsert annotation (both in room2 and room3) now leads to an
UNIQUE constraint failed exceptionat runtime. This also happens after a complete upgrade to room3.This does not happen when using the room2 way with
SupportOpenHelperFactory.This is what Claude analyzed: