Commit 94e5da4
authored
Ignore corrupted ghosts (#216)
* Ignore corrupted ghosts
There are occasions where the stored contents of a ghost may be corrupted
outside of the control of this library. One such occasion was discovered when
sqlite was improperly converting malformed UTF-16 data into UTF-8. In these
cases we risk treating corrupted data as valid and causing more harm to the
ghost and bucket value. Additionally we risk corrupting the JSON structure
stored in the database which can lead to crashes when reading or using it.
In this patch we're performing one simple validation to make sure that we don't
attempt to use a ghost which we cannot parse as JSON. Should the occasion arise
then the library should attempt to retrieve the latest ghost from the server
and start fresh with its processing.
Although it looks like this patch may introduce a vector for losing changes it's
actually closing a vector for an app crash; the data would have never made it in
the first place.
* Rearrange some of the existing code
- According to what I read, `try/catch` blocks with resources are available to
us in the SDK version 19, which I believe we are using. By moving the cursor
into the `try/catch` block it will automatically close the cursor regardless of
whether we raise an exception or return.
- `cursor.moveToFirst()` returns whether or not it was able to find a first result
which means that the call to `cursor.getCount()` was redundant and provided no
information for our needs beyond what we already had.
- since we only return a `Ghost` when all the conditions hold the `ghost` variable
wasn't necessary and only introduced opportunities for creating `null` reference
errors. I took it out to remove that opportunity.1 parent 0e35535 commit 94e5da4
File tree
1 file changed
+12
-11
lines changed- Simperium/src/main/java/com/simperium/android
1 file changed
+12
-11
lines changedLines changed: 12 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | | - | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
0 commit comments