From 1f0e42044dba02a95a4d321c691fcd7234ff49ce Mon Sep 17 00:00:00 2001 From: danilodominguezperez Date: Mon, 9 Oct 2023 20:25:40 -0500 Subject: [PATCH 1/2] Check for SQLException when getting object from SQLite storage --- .../src/main/java/com/simperium/client/Bucket.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Simperium/src/main/java/com/simperium/client/Bucket.java b/Simperium/src/main/java/com/simperium/client/Bucket.java index 04ff9e6..b516dd6 100644 --- a/Simperium/src/main/java/com/simperium/client/Bucket.java +++ b/Simperium/src/main/java/com/simperium/client/Bucket.java @@ -22,6 +22,7 @@ import android.database.Cursor; import android.database.CursorWrapper; +import android.database.SQLException; import androidx.core.util.Consumer; @@ -513,7 +514,15 @@ public T get(String key) throws BucketObjectMissingException { } catch (GhostMissingException e) { throw(new BucketObjectMissingException(String.format("Bucket %s does not have object %s", getName(), key))); } - T object = mStorage.get(key); + + // Check if there isn't an SQLException (e.g. SQLiteBlobTooBigException) to avoid propageting an unchecked + // exception. + T object; + try { + object = mStorage.get(key); + } catch (SQLException e) { + throw(new BucketObjectMissingException(String.format("Bucket %s does not have object %s", getName(), key), e)); + } if (object == null) { throw(new BucketObjectMissingException(String.format("Storage provider for bucket:%s did not have object %s", getName(), key))); } From 45b683bc8445340222df4c80136f7b9fa05d1a89 Mon Sep 17 00:00:00 2001 From: danilodominguezperez Date: Tue, 10 Oct 2023 09:07:22 -0500 Subject: [PATCH 2/2] Add a note about why we should put the check on Bucket --- Simperium/src/main/java/com/simperium/client/Bucket.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Simperium/src/main/java/com/simperium/client/Bucket.java b/Simperium/src/main/java/com/simperium/client/Bucket.java index b516dd6..37a002a 100644 --- a/Simperium/src/main/java/com/simperium/client/Bucket.java +++ b/Simperium/src/main/java/com/simperium/client/Bucket.java @@ -515,8 +515,11 @@ public T get(String key) throws BucketObjectMissingException { throw(new BucketObjectMissingException(String.format("Bucket %s does not have object %s", getName(), key))); } - // Check if there isn't an SQLException (e.g. SQLiteBlobTooBigException) to avoid propageting an unchecked + // Check if there isn't an SQLException (e.g. SQLiteBlobTooBigException) to avoid propagating an unchecked // exception. + // Note: this check should be at the storage level since at the Bucket level we don't know that we are dealing + // with a SQLite storage. However, at this point we have more information about what is happening, thus, it can + // be better reported. T object; try { object = mStorage.get(key);